ios 扑克牌效果轮播_iOS一行代码实现立体轮播图

示例图片

bannergif.gif

使用方法

1. 初始化

(instancetype)initWithFrame:(CGRect)frame WithBannerSource:(NinaBannerSource)bannerSource WithBannerArray:(NSArray *)bannerArray;

2. 设置属性

自动轮播间隔时间

@property (nonatomic, assign) CGFloat timeInterval;

是否要显示pagecontrol

@property (nonatomic, assign) BOOL showPageControl;

当前页点的颜色

@property (nonatomic, strong) UIColor *currentPageIndicatorTintColor;

未选中点的颜色

@property (nonatomic, strong) UIColor *pageIndicatorTintColor;

点击图片回调

(void)hhBannerView:(HHBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index;

实现原理

简介

该控件主要使用iOS核心动画 CoreAnimation中转场动画-立方体翻转效果进行实现

CATransition *transition = [[CATransition alloc] init];

transition.type = @"cube"; //立方体翻转

transition.subtype = kCATransitionFromRight;

transition.duration = 1.5;

transition.delegate = self;

[self.imgView.layer addAnimation:transition forKey:nil];

添加定时器进行自动的翻转

- (void)setupTimer:(CGFloat)timeInterval {

self.myTimer = [NSTimer timerWithTimeInterval:timeInterval target:self selector:@selector(handleSwipeFromRight) userInfo:nil repeats:YES];

[[NSRunLoop currentRunLoop] addTimer:self.myTimer forMode:NSDefaultRunLoopMode];

}

添加左右滑动手势进行翻转动画

监听动画执行开始和结束,在开始时候关闭定时器,并且关闭self.img的触摸事件;在结束时候重新开启定时器,并且打开self.img的触摸事件

UISwipeGestureRecognizer *fromRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromRight)];

[fromRightRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];

[self.imgView addGestureRecognizer:fromRightRecognizer];

UISwipeGestureRecognizer *fromLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromLeft)];

[fromLeftRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];

[self.imgView addGestureRecognizer:fromLeftRecognizer];

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值