UIView动画下


#import "ViewController.h"
 
@interface ViewController ()
{
    UIButton *btn;
}
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    btn=[UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame=CGRectMake(30, 30, 50, 50);
    btn.backgroundColor=[UIColor redColor];
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
     
}
//UIViewAnimationWithBlocks
-(void)btnclick:(id)sender
{
   // 此方法参数1:动画时长 参数2:修改的View的属性
    [UIView animateWithDuration:2 animations:^{
        btn.backgroundColor=[UIColor blackColor];
    }];
     
     
   //此方法参数1:动画时长 参数2:修改的View的属性 参数3:动画完成的回调
   [UIView animateWithDuration:3 animations:^{
       btn.backgroundColor=[UIColor redColor];
   } completion:^(BOOL finished) {
       NSLog(@"completion1");
   }];
   /* UIViewAnimationOptionLayoutSubviews //提交动画的时候布局子控件,表示子控件将和父控件一同动画。
     
    UIViewAnimationOptionAllowUserInteraction //动画时允许用户交流,比如触摸
     
    UIViewAnimationOptionBeginFromCurrentState //从当前状态开始动画
     
    UIViewAnimationOptionRepeat //动画无限重复
     
    UIViewAnimationOptionAutoreverse //执行动画回路,前提是设置动画无限重复
     
    UIViewAnimationOptionOverrideInheritedDuration //忽略外层动画嵌套的执行时间
     
    UIViewAnimationOptionOverrideInheritedCurve //忽略外层动画嵌套的时间变化曲线
     
    UIViewAnimationOptionAllowAnimatedContent //通过改变属性和重绘实现动画效果,如果key没有提交动画将使用快照
     
    UIViewAnimationOptionShowHideTransitionViews //用显隐的方式替代添加移除图层的动画效果
     
    UIViewAnimationOptionOverrideInheritedOptions //忽略嵌套继承的选项
     
    //时间函数曲线相关
     
    UIViewAnimationOptionCurveEaseInOut //时间曲线函数,由慢到快
     
    UIViewAnimationOptionCurveEaseIn //时间曲线函数,由慢到特别快
     
    UIViewAnimationOptionCurveEaseOut //时间曲线函数,由快到慢
     
    UIViewAnimationOptionCurveLinear //时间曲线函数,匀速
     
    //转场动画相关的
     
    UIViewAnimationOptionTransitionNone //无转场动画
     
    UIViewAnimationOptionTransitionFlipFromLeft //转场从左翻转
     
    UIViewAnimationOptionTransitionFlipFromRight //转场从右翻转
     
    UIViewAnimationOptionTransitionCurlUp //上卷转场
     
    UIViewAnimationOptionTransitionCurlDown //下卷转场
     
    UIViewAnimationOptionTransitionCrossDissolve //转场交叉消失
     
    UIViewAnimationOptionTransitionFlipFromTop //转场从上翻转
     
    UIViewAnimationOptionTransitionFlipFromBottom //转场从下翻转
    */
    //参数1 动画时长 参数2 延迟时间 参数3 枚举见上面注释 参数4 改变View属性 参数5 动画完成时回调
    [UIView animateKeyframesWithDuration:2 delay:2 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{
          btn.backgroundColor=[UIColor greenColor];
            CGRect frame=btn.frame;
            if (frame.origin.x<self.view.frame.size.width-20) {
                frame.origin.x+=20;
            }
            else
            {
                frame.origin.x=0;
                 
            }
            btn.frame=frame;
    } completion:^(BOOL finished) {
        NSLog(@"completion2");
    }];
    //转场动画
    [UIView transitionFromView:self.view toView:btn duration:5 options:UIViewAnimationOptionTransitionCurlDown completion:^(BOOL finished) {
        NSLog(@"completion3");
    }];
   [UIView transitionWithView:self.view duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
       btn.backgroundColor=[UIColor redColor];
   } completion:^(BOOL finished) {
       NSLog(@"completion4");
   }];
   
}
 
 
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end

上一篇:zabbix自动监控网络设备juniper防火墙


下一篇:TensorFlow新功能解锁:可在TensorBoard中增加自定义可视化插件