介绍
这篇文章给大家分享的是有关iOS如何实现带有缩放效果的自动轮播图的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
可直接设置框架然后加载到视图上使用。
效果就是这样的,图片切换的过程中还是有卡顿,不够流畅,后续更新。
直接上代码。
。h文件包含:
# import & lt; UIKit/UIKit.h>, , @interface CustomScrollView : UIView @property (强,原子),NSArray * imageArr;, , @end
。米文件包含:
# import “CustomScrollView.h", , @interface CustomScrollView () & lt; UIScrollViewDelegate>, , @property (强,原子),UIScrollView *滚动视图;, @property (强,原子),UIImageView * backImageView;, , @property (强,原子),UIImageView * leftIamgeView;, @property (强,原子),UIImageView * middleImageView;, @property (强,原子),UIImageView * rightImageView;, , @property (强,原子),UIPageControl * pageControl;, ,//高度, @property (分配、原子),CGFloat scrollViewHeight;, ,//手动造成的偏移量, @property (分配、原子),CGFloat offsetX;, , @property (强,原子),NSTimer *计时器;, ,//属于计时器方法动画持续时间,?, @property (分配、原子),BOOL timerAnimation;, , @end ,//左右内容的最大偏移量, # define OFFSET_MAX ([UIScreen mainScreen] .bounds.size.width - 64) * 0.9, , , @implementation CustomScrollView , 安康;(instancetype) initWithFrame:(CGRect中)frame {, ,if (self =, [super initWithFrame:框架]),{, ,=,,self.scrollViewHeight  frame.size.height;, , ,[self addSubview self.backImageView):,, ,[self addSubview self.scrollView):,, ,[self addSubview self.pageControl):,, , ,(self.backImageView mas_makeConstraints: ^ (MASConstraintMaker *), {, ,make.edges.with.mas_equalTo(自我),, ,}]; ,(self.scrollView mas_makeConstraints: ^ (MASConstraintMaker *), {, ,make.edges.with.mas_equalTo(自我),, ,}]; ,(self.pageControl mas_makeConstraints: ^ (MASConstraintMaker *), {, ,make.left.right.bottom.mas_equalTo(自我),, ,make.height.mas_equalTo (@20);, ,}]; ,=,self.timer [NSTimer scheduledTimerWithTimeInterval: 5,目标:self 选择器:@ selector (timerAction),用户信息:nil 重复:是的),, mainRunLoop], [[NSRunLoop addTimer: self.timer forMode: NSDefaultRunLoopMode];, ,(self.timer setFireDate: [NSDate dateWithTimeIntervalSinceNow: 5]];, }大敌; ,return 自我; }, , 安康;(NSArray *) imageArr {, ,if (! _imageArr), {,=,_imageArr @ [@" timg-0" @" timg-1", @" timg-2"];, }大敌; ,return _imageArr; }, , 安康;(UIImageView *) backImageView {, ,if (! _backImageView), {,=,_backImageView [[UIImageView alloc], init),,=,_backImageView.image [UIImage imageNamed: @" bg_home"];, }大敌; ,return _backImageView; }, , 安康;(UIScrollView *) scrollView {, ,if (! _scrollView), {,=,_scrollView [[UIScrollView alloc], init),,=,_scrollView.showsVerticalScrollIndicator 不,,=,_scrollView.showsHorizontalScrollIndicator 不,,=,,_scrollView.contentSize  CGSizeMake (kScreenWidth + 2 * OFFSET_MAX, self.scrollViewHeight),, ,(_scrollView setContentOffset: CGPointMake (OFFSET_MAX,, 0)];,=,_scrollView.bounces 不,,=,_scrollView.delegate 自我;, ,=,_leftIamgeView [[UIImageView alloc], init),,=,_leftIamgeView.image [UIImage imageNamed: self.imageArr [0]),,=,_leftIamgeView.layer.cornerRadius 5,,=,_leftIamgeView.layer.masksToBounds 是的,, , ,=,_middleImageView [[UIImageView alloc], init),,=,_middleImageView.image [UIImage imageNamed: self.imageArr [1]];,=,_middleImageView.layer.cornerRadius 5,,=,_middleImageView.layer.masksToBounds 是的,, , ,=,_rightImageView [[UIImageView alloc], init),,=,_rightImageView.image [UIImage imageNamed: self.imageArr [2]];, null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null nulliOS如何实现带有缩放效果的自动轮播图