Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 4 Application Development
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 5th, 2011, 01:26 PM
Authorized User
Points: 92, Level: 1
Points: 92, Level: 1 Points: 92, Level: 1 Points: 92, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #2 (permalink)  
Old June 5th, 2011, 08:39 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #3 (permalink)  
Old June 5th, 2011, 08:47 PM
Authorized User
Points: 92, Level: 1
Points: 92, Level: 1 Points: 92, Level: 1 Points: 92, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:54 AM.


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