UIView 实现反转效果

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.


    

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    btn.backgroundColor = [UIColor redColor];

    btn.frame = CGRectMake(10, 90, 100, 50);

    [self.view addSubview:btn];

    [btn addTarget:self action:@selector(ActionFanzhuan) forControlEvents:UIControlEventTouchUpInside];

    

    

    //需要翻转的视图

    UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)];

    parentView.backgroundColor = [UIColor yellowColor];

    parentView.tag = 1000;

    [self.view addSubview:parentView];

}

//需要在h头文件声明下面的动作响应函数

//xib文件中添加一个button,其响应函数为下面的函数

//运行程序后,点击button就看到翻转效果

-(void)ActionFanzhuan{

    //获取当前画图的设备上下文

    CGContextRef context = UIGraphicsGetCurrentContext();

    //开始准备动画

    [UIView beginAnimations:nil context:context];

    //设置动画曲线,翻译不准,见苹果官方文档

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //设置动画持续时间

    [UIView setAnimationDuration:1.0];

    //因为没给viewController类添加成员变量,所以用下面方法得到viewDidLoad添加的子视图

    UIView *parentView = [self.view viewWithTag:1000];

    //设置动画效果

    [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES];  //从上向下

    // [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES];   //从下向上

    // [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES];  //从左向右

    // [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//从右向左

    //设置动画委托

    [UIView setAnimationDelegate:self];

    //当动画执行结束,执行animationFinished方法

    [UIView setAnimationDidStopSelector:@selector(animationFinished:)];

    //提交动画

    [UIView commitAnimations];

}


//动画效果执行完毕

- (void) animationFinished: (id) sender{

    NSLog(@"animationFinished !");

}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值