Swift3.0学习之ScrollView的简单使用

1、创建scrollview

self.frame = CGRect(x: rect.origin.x, y: 0, width: rect.size.width, height: rect.size.height)
        
        
        self.contentSize = CGSize(width: CGFloat(imageNames.count ) * self.bounds.width,height: rect.size.height)      
        self.bounces = false
        self.isPagingEnabled = true
        self.showsVerticalScrollIndicator = false
        self.showsHorizontalScrollIndicator = false
        
        
        for i in 0...(imageNames.count - 1) {
            let imageView = UIImageView.init(frame: CGRect(x: CGFloat(i) * self.bounds.width, y: 0, width: self.bounds.width, height: rect.size.height))
            self.addSubview(imageView)
            imageView.contentMode = .scaleAspectFill
            imageView.image = UIImage(named: imageNames[i])
        }

2、创建pagecontrol

pageControl = UIPageControl.init(frame: CGRect(x: (rect.size.width - 100)*0.5, y: rect.size.height - 30, width: 100, height: 20))
        
        pageControl.numberOfPages = imageNames.count
        pageControl.pageIndicatorTintColor = pageIndicatorTintColor
        pageControl.currentPageIndicatorTintColor = currentPageIndicatorTintColor
        //将小白点放到scr之上
        view.insertSubview(pageControl, aboveSubview: scrollView)   
3、创建自动轮播的计时器

 timer =  Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(self.timerManager), userInfo: nil, repeats: true)

func timerManager() {
        //实现方法
    }
4、实现代理方法

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
    }
在滚动时可以添加动画,使移动时视觉效果增强

UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.3)//时间
UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut)
  //移动路径

UIView.commitAnimations()




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值