輪翻播放與查看是分開的,輪翻是是用 開源的SDCycleScrollView
創(chuàng)新互聯(lián)專注于企業(yè)成都營銷網(wǎng)站建設、網(wǎng)站重做改版、孫吳網(wǎng)站定制設計、自適應品牌網(wǎng)站建設、H5場景定制、電子商務商城網(wǎng)站建設、集團公司官網(wǎng)建設、外貿(mào)營銷網(wǎng)站建設、高端網(wǎng)站制作、響應式網(wǎng)頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為孫吳等各大城市提供網(wǎng)站開發(fā)制作服務。這里是給出的是查看的:
// // FullScreenShowImageView.swift // joopic // // Created by jianxiong li on 16/9/27. // Copyright © 2016年 joobot. All rights reserved. // import Foundation import UIKit //圖片輪播組件代理協(xié)議 protocol FullScreenShowImageViewDelegate{ //獲取數(shù)據(jù)源 func galleryDataSource()->[String] //獲取內(nèi)部scrollerView的寬高尺寸 func galleryScrollerViewSize()->CGSize func hiddenForCliked(index:Int) } //圖片輪播組件控制器 class FullScreenShowImageView: UIView,UIScrollViewDelegate{ //代理對象 var delegate : FullScreenShowImageViewDelegate! //屏幕寬度 let kScreenWidth = BWidth //當前展示的圖片索引 var currentIndex : Int = 0 //數(shù)據(jù)源 var dataSource : [String]? //用于輪播的左中右三個image(不管幾張圖片都是這三個imageView交替使用) var leftImageView , middleImageView , rightImageView : UIImageView? //放置imageView的滾動視圖 var scrollerView : UIScrollView? //scrollView的寬和高 var scrollerViewWidth : CGFloat? var scrollerViewHeight : CGFloat? //頁控制器(小圓點) var pageControl : UIPageControl? //加載指示符(用來當iamgeView還沒將圖片顯示出來時,顯示的圖片) var placeholderImage:UIImage! //自動滾動計時器 var autoScrollTimer:NSTimer? init(frame: CGRect,delegate:FullScreenShowImageViewDelegate) { super.init(frame: frame) self.delegate = delegate praperaUI() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func praperaUI() { //獲取并設置scrollerView尺寸 let size : CGSize = self.delegate.galleryScrollerViewSize() self.scrollerViewWidth = size.width self.scrollerViewHeight = size.height //獲取數(shù)據(jù) self.dataSource = self.delegate.galleryDataSource() //設置scrollerView self.configureScrollerView() //設置加載指示圖片 self.configurePlaceholder() //設置imageView self.configureImageView() //設置頁控制器 self.configurePageController() //設置自動滾動計時器 //self.configureAutoScrollTimer() self.backgroundColor = UIColor.blackColor() self.addTapAction() } func addTapAction(){ //添加組件的點擊事件 let tap = UITapGestureRecognizer(target: self, action: #selector(FullScreenShowImageView.handleTapAction(_:))) self.addGestureRecognizer(tap) } //點擊事件響應 func handleTapAction(tap:UITapGestureRecognizer)->Void{ //獲取圖片索引值 self.delegate.hiddenForCliked(self.currentIndex) self.dismissViewAnimate() } func presentViewAnimate() { let fr = self.middleImageView?.frame self.middleImageView?.frame = CGRect(x: fr!.origin.x, y: 22, width: fr!.width, height: fr!.height) UIView.animateWithDuration(10, animations: { self.middleImageView?.frame = fr! }) { (_) in } } func dismissViewAnimate() { let fr = self.middleImageView?.frame self.middleImageView?.frame = CGRect(x: fr!.origin.x, y: fr!.origin.y - StatusAndNavHeight, width: fr!.width, height: fr!.height) UIView.animateWithDuration(10, animations: { self.middleImageView?.frame = CGRect(x: fr!.origin.x , y: -42, width: fr!.width, height: fr!.height) }) { (_) in self.hidden = true self.middleImageView?.frame = fr! } } //設置scrollerView func configureScrollerView(){ self.scrollerView = UIScrollView(frame: CGRect(x: 0,y: 0, width: self.scrollerViewWidth!, height: BHeight)) self.scrollerView?.backgroundColor = UIColor.blackColor() self.scrollerView?.delegate = self self.scrollerView?.contentSize = CGSize(width: self.scrollerViewWidth! * 3, height: BHeight) //滾動視圖內(nèi)容區(qū)域向左偏移一個view的寬度 self.scrollerView?.contentOffset = CGPoint(x: self.scrollerViewWidth!, y: 0) self.scrollerView?.pagingEnabled = true self.scrollerView?.bounces = false self.addSubview(self.scrollerView!) } //設置加載指示圖片 func configurePlaceholder(){ //這里我使用ImageHelper將文字轉換成圖片,作為加載指示符 let font = UIFont.systemFontOfSize(17)// UIFont.systemFont(ofSize: 17.0, weight: UIFontWeightMedium) let size = CGSize(width: self.scrollerViewWidth!, height: self.scrollerViewHeight!) placeholderImage = UIImage(named: "圖片加載中...") } //設置imageView func configureImageView(){ self.leftImageView = UIImageView(frame: CGRect(x: 0, y: (BHeight-scrollerViewHeight!)/2, width: self.scrollerViewWidth!, height: self.scrollerViewHeight!)) self.middleImageView = UIImageView(frame: CGRect(x: self.scrollerViewWidth!, y: (BHeight-scrollerViewHeight!)/2, width: self.scrollerViewWidth!, height: self.scrollerViewHeight! )); self.rightImageView = UIImageView(frame: CGRect(x: 2*self.scrollerViewWidth!, y: (BHeight-scrollerViewHeight!)/2, width: self.scrollerViewWidth!, height: self.scrollerViewHeight!)); self.scrollerView?.showsHorizontalScrollIndicator = false self.leftImageView?.contentMode = UIViewContentMode.ScaleAspectFit self.middleImageView?.contentMode = UIViewContentMode.ScaleAspectFit self.rightImageView?.contentMode = UIViewContentMode.ScaleAspectFit //設置初始時左中右三個imageView的圖片(分別時數(shù)據(jù)源中最后一張,第一張,第二張圖片) if(self.dataSource?.count != 0){ resetImageViewSource() } self.scrollerView?.addSubview(self.leftImageView!) self.scrollerView?.addSubview(self.middleImageView!) self.scrollerView?.addSubview(self.rightImageView!) } //設置頁控制器 func configurePageController() { self.pageControl = UIPageControl(frame: CGRect(x: kScreenWidth/2-60, y: BHeight - 30, width: 120, height: 20)) self.pageControl?.numberOfPages = (self.dataSource?.count)! self.pageControl?.userInteractionEnabled = false self.addSubview(self.pageControl!) } //設置自動滾動計時器 func configureAutoScrollTimer() { //設置一個定時器,每三秒鐘滾動一次 autoScrollTimer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: #selector(SliderGalleryController.letItScroll), userInfo: nil, repeats: true) } //計時器時間一到,滾動一張圖片 func letItScroll(){ let offset = CGPoint(x: 2*scrollerViewWidth!, y: 0) self.scrollerView?.setContentOffset(offset, animated: true) } //每當滾動后重新設置各個imageView的圖片 func resetImageViewSource() { //當前顯示的是第一張圖片 if self.currentIndex == 0 { self.leftImageView?.sd_setImageWithURL(NSURL(string: self.dataSource!.last!)) self.middleImageView?.sd_setImageWithURL(NSURL(string: self.dataSource!.first!)) let rightImageIndex = (self.dataSource?.count)!>1 ? 1 : 0 //保護 self.rightImageView?.sd_setImageWithURL(NSURL(string: self.dataSource![rightImageIndex])) } //當前顯示的是最后一張圖片 else if self.currentIndex == (self.dataSource?.count)! - 1 { self.leftImageView?.sd_setImageWithURL(NSURL(string:self.dataSource![self.currentIndex-1])) self.middleImageView?.sd_setImageWithURL(NSURL(string: self.dataSource!.last!)) self.rightImageView?.sd_setImageWithURL(NSURL(string: self.dataSource!.first!)) } //其他情況 else{ self.leftImageView?.sd_setImageWithURL(NSURL(string:self.dataSource![self.currentIndex-1])) self.middleImageView?.sd_setImageWithURL(NSURL(string: self.dataSource![self.currentIndex])) self.rightImageView?.sd_setImageWithURL(NSURL(string: self.dataSource![self.currentIndex+1])) } //設置頁控制器當前頁碼 self.pageControl?.currentPage = self.currentIndex } //scrollView滾動完畢后觸發(fā) func scrollViewDidScroll(scrollView: UIScrollView) { //獲取當前偏移量 let offset = scrollView.contentOffset.x if(self.dataSource?.count != 0){ //如果向左滑動(顯示下一張) if(offset >= self.scrollerViewWidth!*2){ //還原偏移量 scrollView.contentOffset = CGPoint(x: self.scrollerViewWidth!, y: 0) //視圖索引+1 self.currentIndex = self.currentIndex + 1 if self.currentIndex == self.dataSource?.count { self.currentIndex = 0 } } //如果向右滑動(顯示上一張) if(offset <= 0){ //還原偏移量 scrollView.contentOffset = CGPoint(x: self.scrollerViewWidth!, y: 0) //視圖索引-1 self.currentIndex = self.currentIndex - 1 if self.currentIndex == -1 { self.currentIndex = (self.dataSource?.count)! - 1 } } //重新設置各個imageView的圖片 resetImageViewSource() } } //手動拖拽滾動開始 func scrollViewWillBeginDragging(scrollView: UIScrollView) { //使自動滾動計時器失效(防止用戶手動移動圖片的時候這邊也在自動滾動) //autoScrollTimer?.invalidate() } //手動拖拽滾動結束 func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { //重新啟動自動滾動計時器 //configureAutoScrollTimer() } }
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站www.rwnh.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
本文標題:iOS開發(fā)商品頁中banner中點擊查看圖片-創(chuàng)新互聯(lián)
網(wǎng)頁URL:http://www.rwnh.cn/article16/dosddg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、做網(wǎng)站、動態(tài)網(wǎng)站、用戶體驗、搜索引擎優(yōu)化、品牌網(wǎng)站設計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容