博客> iOS开发实现底部横幅广告切换动画效果
iOS开发实现底部横幅广告切换动画效果
2017-09-23 09:24 评论:0 阅读:138 3559741123
iOS动画 iOS切换

今天来实现类似于腾讯底部广告翻转切换view的效果,我想这个效果大家都有印象! 大概思路是通过[UIView transitionFromView]方法切换专场动画来实现的! 废话不多说,直接上代码。


@interface ViewController ()

@property(strong,nonatomic)UIView *blueView;
@property(strong,nonatomic)UIView *yellowView;
/**<#属性名字#>*/
@property(nonatomic,assign) BOOL changeFlag;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.changeFlag = YES;
    self.view.backgroundColor = [UIColor redColor];

    /**底部容器view*/
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    backView.backgroundColor = [UIColor whiteColor];
    backView.clipsToBounds = YES;
    [self.view addSubview:backView];

    /**黄色View*/
    UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    yellowView.backgroundColor = [UIColor yellowColor];
    [backView addSubview:yellowView];
    self.yellowView = yellowView;

    /**蓝色View*/
    UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    blueView.backgroundColor = [UIColor blueColor];
    [backView addSubview:blueView];
    self.blueView = blueView;
}

- (void)touchesBegan:(NSSet<UITouch> *)touches withEvent:(UIEvent *)event {
    /**点击切换事件*/
    if (self.changeFlag) {
        [UIView transitionFromView:self.blueView toView:self.yellowView duration:0.25 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {
            self.changeFlag = !self.changeFlag;
        }];
    }else{
        [UIView transitionFromView:self.yellowView toView:self.blueView duration:0.25 options:UIViewAnimationOptionTransitionFlipFromTop completion:^(BOOL finished) {
            self.changeFlag = !self.changeFlag;
        }];
    }
}

@end

拷贝代码运行看效果!完美实现

// 欢迎大家下载我的app:《咱们聊天吧》和《微文大杂烩》 ,上传你心目中女神照片,起上她的名字,平时不敢说的话都可以在这里发泄,还有各种段子,图片,文字游戏等等!,打造最强(wei)大(suo)人工智能,赶快下载看看吧. // /***/

收藏
0
sina weixin mail 回到顶部