Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-11-2011, 07:26 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 7
springfieldx is on a distinguished road
Default Tips for UIView animation: Using Blocks

For our developers, UIView animation has already been familiar to us. We can use this mechanism easily to implement awesome animation effects with very little code. A simple example like that:
Code:
  viewToAnimate.alpha = 0;
  
  [UIView animateWithDuration:1.0f animations:^{
  
    viewToAnimate.alpha = 1;
    
  }];
The code described above is a fade in effect. With UIView animation, we just need to use this 4 lines of code. The ^{...} syntax is Blocks introduced from iOS 4. Furthermore, the benefit of Blocks is more than that. For example, if the animation we needed is two or more steps, such as we want it fade in first and then zoom in. In traditional way, we should use the delegate of the completion of the animation and implement a method to do that . But with Blocks, it more straightforward:

Code:
  
  viewToAnimate.alpha = 0;
  
  [UIView animateWithDuration:1.0f 
                   animations:^{
                     
    viewToAnimate.alpha = 1;
                     
  }completion:^(BOOL finished){

    [UIView animateWithDuration:1.0f animations:^{                     
    
      viewToAnimate.frame = CGRectMake(50, 50, 200, 200);
      
    }];
                     
  }];
Our code using a completion Block to handle the complete of the animation. In the completion block, we create another animation block which zoom in our view. The result is that the view first fade in and then zoom in. With Blocks, we can do these all things in the same domain rather than separate them to divided methods. It could greatly improve our productivity specially for the animations which has serval steps.
springfieldx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 406
13 members and 393 guests
7twenty7, AppsBlogger, Creativ, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0