[UIView beginAnimations…]; is a class method that indicates the beginning of an animation block. The various properties are set (duration, curve). The setAnimationTransition:forView:
theView informs what view the transition applies to etc. [UIView commitAnimations]; closes the block.
http://developer.apple.com/library/i...009503-CH6-SW1
Has a substantial discussion on the topic.
The manner in which the block and the animatable properties are defined has changed in iOS 4. The blocks actually use blocks (closures).
In the HelloWorldViewController the 2 rewrites with the now recommended blocks approach are in bold (one obviously commented out)
Code:
-(IBAction) btnClicked:(id) sender{
/*
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
forView:self.view.superview cache:YES];
//—-remove the current view; essentially hiding the view—-
[self.view removeFromSuperview];
[UIView commitAnimations];
*/
/*
//////Block version number 1
[UIView animateWithDuration:1 animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view.superview cache:YES];
[self.view removeFromSuperview];}];
*/
//////Block version number 2
[UIView transitionWithView:self.view.superview duration:1
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionTransitionFlipFromRight
animations:^{[self.view removeFromSuperview];}
completion:nil];
}
similarly in MySecondViewController
Code:
-(IBAction) buttonClicked: (id) sender{
//—-add the view of the view controller to the current View—-
viewController = [[HelloWorldViewController alloc]
initWithNibName:@"HelloWorldViewController"
bundle:nil];
/*
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft
forView:self.view cache:YES];
[self.view addSubview:viewController.view];
[UIView commitAnimations];
*/
/*
//////Block version number 1
[UIView animateWithDuration:1 animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.view addSubview:viewController.view];}];
*/
//////Block version number 2
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionTransitionFlipFromLeft
animations:^{[self.view addSubview:viewController.view];}
completion:nil];
/*
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Action invoked!"
message:@"Button clicked!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
*/
}
Basically the properties set in the class method are used in the current animation.
Move to C++ and lose all fun and flexibility that comes with dynamic binding!?!? NEVER!
Bob