Wrox Programmer Forums
|
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2011, 01:26 PM
Authorized User
 
Join Date: May 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4, Animating switching of views

Pages 101-103 provide a "try it out" to animate switching of views. It works. But how does Objective C associate the [UIView...] statements with the relevant view? UIView is a class, not an object, correct? My C++ experience [perhaps part of my problem] suggests that calling a method of a [static] class may be useful as an r-value, e.g., [UIColor clearColor], but on pages 101-103 UIView isn't used as an r-value but somehow has an effect on the view. What is the connection?

I suppose praying that Apple move from Objective C to C++ would not be helpful, correct?
 
Old June 5th, 2011, 08:39 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

[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

Last edited by thepianoguy; June 5th, 2011 at 08:41 PM.. Reason: addendum
 
Old June 5th, 2011, 08:47 PM
Authorized User
 
Join Date: May 2011
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So the messages to UIView are tweaking static members of a static class? And then when you "commit" the animation, the tweaks you've performed have their effect?

But what if more than one thread is simultaneously tweaking the static class?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4 - Switching Views tfiPadn00b BOOK: Beginning iPad Application Development 5 December 20th, 2010 11:01 AM
Chapter 4 - Two Views, not working for me... bigtalk BOOK: Beginning Ruby on Rails 1 January 3rd, 2008 07:30 AM
Chapter 7 - List Views Not Refreshing VBNovice BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 January 31st, 2007 08:26 PM
animating screen snapshots ringo VB How-To 2 April 10th, 2005 12:57 PM
converting Access 2000 views to Sql views matta Classic ASP Professional 1 January 26th, 2005 03:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.