【Animation】Animating Sample Code

1. Performing a simple block-based animation 

[UIView animateWithDuration:1.0 animations:^{
          firstView.alpha = 0.0;
          secondView.alpha = 1.0;
}];

The animations in the preceding example run only once using an ease-in, ease-out animation curve.  


2.  Creating an animation block with custom options 

- (IBAction)showHideView:(id)sender
  {
      // Fade out the view right away
      [UIView animateWithDuration:1.0
          delay: 0.0
          options: UIViewAnimationOptionCurveEaseIn
animations:^{
               thirdView.alpha = 0.0;
          }
          completion:^(BOOL finished){

// Wait one second and then fade in the view
[UIView animateWithDuration:1.0
     delay: 1.0
     options:UIViewAnimationOptionCurveEaseOut
     animations:^{
        thirdView.alpha = 1.0;
     }
     completion:nil];<pre name="code" class="objc" style="font-size: 13px;">    }]; 
}

 
   

Using a completion handler is the primary way that you link multiple animations. 

3.  Performing a simple begin/commit animation (iOS 3.2  and earlier)

[UIView beginAnimations:@"ToggleViews" context:nil];
[UIView setAnimationDuration:1.0];
// Make the animatable changes.
firstView.alpha = 0.0;
secondView.alpha = 1.0;
// Commit the changes and perform the animation.
[UIView commitAnimations];


4.  Nesting animations that have different configurations 

[UIView animateWithDuration:1.0
          delay: 1.0
          options:UIViewAnimationOptionCurveEaseOut
          animations:^{
              aView.alpha = 0.0;
// Create a nested animation that has a different
              // duration, timing curve, and configuration.
              [UIView animateWithDuration:0.2
                   delay:0.0
                   options: UIViewAnimationOptionOverrideInheritedCurve |
                            UIViewAnimationOptionCurveLinear |
                            UIViewAnimationOptionOverrideInheritedDuration |
                            UIViewAnimationOptionRepeat |
                            UIViewAnimationOptionAutoreverse
                   animations:^{
                        [UIView setAnimationRepeatCount:2.5];
                        anotherView.alpha = 0.0;
                   }
                   completion:nil];
          }
          completion:nil];

The UIViewAnimationOptionOverrideInheritedCurveandUIViewAnimationOptionOverrideInheritedDurationkeys used in the nested animation block allowthe curve and duration values from the first animation to be modified for the second animation. If these keyswere not present, the duration and curve of the outer animation block would be used instead. 


5.  Changing the Subviews of a View 

- (IBAction)displayNewPage:(id)sender
{
    [UIView transitionWithView:self.view
        duration:1.0
        options:UIViewAnimationOptionTransitionCurlUp
        animations:^{
            currentTextView.hidden = YES;
            swapTextView.hidden = NO;
        }
        completion:^(BOOL finished){
            // Save the old text and then swap the views.
            [self saveNotes:temp];
            UIView*    temp = currentTextView;
            currentTextView = swapTextView;
            swapTextView = temp;
}]; }



6. 

Replacing a View with a Different View 

- (IBAction)toggleMainViews:(id)sender {
    [UIView transitionFromView:(displayingPrimary ? primaryView : secondaryView)
:
}
toView:(displayingPrimary ? secondaryView : primaryView)
duration:1.0
options:(displayingPrimary ? UIViewAnimationOptionTransitionFlipFromRight
            UIViewAnimationOptionTransitionFlipFromLeft)
completion:^(BOOL finished) {
    if (finished) {
        displayingPrimary = !displayingPrimary;
} }];







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值