Lets do some twists in iOS

Ever wondered how you can turn a view along the x-axis or y-axis. You can do that using the CATransform3DMakeRotation in iOS. Its pretty cool. You can use animation to even make it more awesome.
In the CATransform3DMakeRotation method you can change the x,y,z values to 1 for rotating the views along the respective axis. Some uses are  giving the user a page flip, or rotating view impression. I mean there is more, but here is some code –
[sourcecode lang=”objc”]
// use a gesture recognizer
UISwipeGestureRecognizer* swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[reminderView2 addGestureRecognizer:swipeGesture];
}
static BOOL turn = YES;
-(void) handleSwipe:(UITapGestureRecognizer*) recognizer{
UIView *myView = recognizer.view;
[UIView animateWithDuration:1.0f animations:^{
if (turn) {
myView.layer.transform = CATransform3DMakeRotation(M_PI,1.0f, 0.0f, 0.0f);
turn = NO;
}else{
turn = YES;
// i am rotating it back another 360 degrees, back to square one
myView.layer.transform = CATransform3DMakeRotation(-M_PI*2,1.0f, 0.0f, 1.0f);
}
} completion:^(BOOL finished) {
if (turn) {
[myView setBackgroundColor:[UIColor greenColor]];
}else{
[myView setBackgroundColor:[UIColor purpleColor]];
}
}];
}
[/sourcecode]

Leave a Reply

Your email address will not be published. Required fields are marked *