ios 视图动画翻转效果

虽然,网上有很多代码,但是 还是觉得自己写了一个简单的动画翻转的效果,

会更加熟悉些。下面把代码贴出来学习学习。


- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *flipButton=[[UIBarButtonItem alloc]
                                 initWithTitle:@"翻转"
                                 style:UIBarButtonItemStyleBordered
                                 target:self
                                 action:@selector(flip:)];
    self.navigationItem.rightBarButtonItem=flipButton;
    
    
    fistView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    fistView.tag=100;
    fistView.backgroundColor=[UIColor redColor];
    [self.view addSubview:fistView];
    
    secondView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    secondView.tag=101;
    secondView.backgroundColor=[UIColor yellowColor];
    [self.view addSubview:secondView];
}


-(void)flip:(id)sender{
    
    CGContextRef context=UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
   

   //这里时查找视图里的子视图(这种情况查找,可能时因为父视图里面不只两个视图)
    NSInteger fist= [[self.view subviews] indexOfObject:[self.view viewWithTag:100]];
    NSInteger seconde= [[self.view subviews] indexOfObject:[self.view viewWithTag:101]];
    
    [self.view exchangeSubviewAtIndex:fist withSubviewAtIndex:seconde];

   //当父视图里面只有两个视图的时候,可以直接使用下面这段.

    //[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];


    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值