实例讲解iOS中的CATransition转场动画使用

2020-01-15 16:28:06王振洲

    [self.scrollView addSubview:view2];
    self.view2 = view2;

    // 2. scrollView 添加 view1 子控件
    UIView *view1 = [[UIView alloc] init];
    view1.backgroundColor = [UIColor redColor];

    [self.scrollView addSubview:view1];
    self.view1 = view1;

    // 3. frame
    CGFloat scrollViewW = self.scrollView.frame.size.width;
    CGFloat scrollViewH = self.scrollView.frame.size.height;

    view1.frame = CGRectMake(0, 0, scrollViewW, scrollViewH);
    view2.frame = CGRectMake(0, 0, scrollViewW, scrollViewH); // CGRectMake(scrollViewW, 0, scrollViewW, scrollViewH);

    // 4. scrollView
    self.scrollView.contentSize = CGSizeMake(scrollViewW, scrollViewH);
    // 添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [self.scrollView addGestureRecognizer:tap];
}

int i = 1;

// 监听到点击scrollView,进行翻转动画
- (void)tapClick:(UITapGestureRecognizer *)tap{

    if (i % 2 != 0) {

        [UIView transitionFromView:self.view1 toView:self.view2 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromTop completion:nil];

    }else{
        [UIView transitionFromView:self.view2 toView:self.view1 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromBottom completion:nil];
    }

    i++;
}



注:相关教程知识阅读请移步到IOS开发频道。