欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS開發(fā)商品頁中banner中點(diǎn)擊查看圖片

 更新時(shí)間:2018年02月02日 16:21:19   投稿:laozhang  
本文文章給大家列出了關(guān)于iOS開發(fā)商品頁中banner中點(diǎn)擊查看圖片功能源碼,有興趣的朋友參考下吧。

輪翻播放與查看是分開的,輪翻是是用 開源的SDCycleScrollView

這里是給出的是查看的:

//
// 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
 
 //當(dāng)前展示的圖片索引
 var currentIndex : Int = 0
 
 //數(shù)據(jù)源
 var dataSource : [String]?
 
 //用于輪播的左中右三個(gè)image(不管幾張圖片都是這三個(gè)imageView交替使用)
 var leftImageView , middleImageView , rightImageView : UIImageView?
 
 //放置imageView的滾動視圖
 var scrollerView : UIScrollView?
 
 //scrollView的寬和高
 var scrollerViewWidth : CGFloat?
 var scrollerViewHeight : CGFloat?
 
 //頁控制器(小圓點(diǎn))
 var pageControl : UIPageControl?
 
 //加載指示符(用來當(dāng)iamgeView還沒將圖片顯示出來時(shí),顯示的圖片)
 var placeholderImage:UIImage!
 
 //自動滾動計(jì)時(shí)器
 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() {
  
  //獲取并設(shè)置scrollerView尺寸
  let size : CGSize = self.delegate.galleryScrollerViewSize()
  self.scrollerViewWidth = size.width
  self.scrollerViewHeight = size.height
  
  //獲取數(shù)據(jù)
  self.dataSource = self.delegate.galleryDataSource()
  //設(shè)置scrollerView
  self.configureScrollerView()
  
  //設(shè)置加載指示圖片
  self.configurePlaceholder()
  
  //設(shè)置imageView
  self.configureImageView()
  
  //設(shè)置頁控制器
  self.configurePageController()
  
  //設(shè)置自動滾動計(jì)時(shí)器
  //self.configureAutoScrollTimer()
  
  self.backgroundColor = UIColor.blackColor()
  
  self.addTapAction()
 }
  
 func addTapAction(){
  //添加組件的點(diǎn)擊事件
  let tap = UITapGestureRecognizer(target: self,
           action: #selector(FullScreenShowImageView.handleTapAction(_:)))
  self.addGestureRecognizer(tap)
 }
 
 //點(diǎn)擊事件響應(yīng)
 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!
  }
  
 }
 
 //設(shè)置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ū)域向左偏移一個(gè)view的寬度
  self.scrollerView?.contentOffset = CGPoint(x: self.scrollerViewWidth!, y: 0)
  self.scrollerView?.pagingEnabled = true
  self.scrollerView?.bounces = false
  self.addSubview(self.scrollerView!)
  
 }
 
 //設(shè)置加載指示圖片
 func configurePlaceholder(){
  //這里我使用ImageHelper將文字轉(zhuǎn)換成圖片,作為加載指示符
  let font = UIFont.systemFontOfSize(17)// UIFont.systemFont(ofSize: 17.0, weight: UIFontWeightMedium)
  let size = CGSize(width: self.scrollerViewWidth!, height: self.scrollerViewHeight!)
  placeholderImage = UIImage(named: "圖片加載中...")
 }
 
 //設(shè)置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
  
  //設(shè)置初始時(shí)左中右三個(gè)imageView的圖片(分別時(shí)數(shù)據(jù)源中最后一張,第一張,第二張圖片)
  if(self.dataSource?.count != 0){
   resetImageViewSource()
  }
  
  self.scrollerView?.addSubview(self.leftImageView!)
  self.scrollerView?.addSubview(self.middleImageView!)
  self.scrollerView?.addSubview(self.rightImageView!)
 }
 
 //設(shè)置頁控制器
 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!)
 }
 
 //設(shè)置自動滾動計(jì)時(shí)器
 func configureAutoScrollTimer() {
  //設(shè)置一個(gè)定時(shí)器,每三秒鐘滾動一次
  autoScrollTimer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: #selector(SliderGalleryController.letItScroll), userInfo: nil, repeats: true)
 }
 
 //計(jì)時(shí)器時(shí)間一到,滾動一張圖片
 func letItScroll(){
  let offset = CGPoint(x: 2*scrollerViewWidth!, y: 0)
  self.scrollerView?.setContentOffset(offset, animated: true)
 }
 
 //每當(dāng)滾動后重新設(shè)置各個(gè)imageView的圖片
 func resetImageViewSource() {
  //當(dāng)前顯示的是第一張圖片
  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 //保護(hù)
   self.rightImageView?.sd_setImageWithURL(NSURL(string: self.dataSource![rightImageIndex]))
   
   
  }
   //當(dāng)前顯示的是最后一張圖片
  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]))
  }
  
  //設(shè)置頁控制器當(dāng)前頁碼
  self.pageControl?.currentPage = self.currentIndex
 }
 
 
 //scrollView滾動完畢后觸發(fā)
 func scrollViewDidScroll(scrollView: UIScrollView) {
  //獲取當(dāng)前偏移量
  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
    }
   }
   
   //重新設(shè)置各個(gè)imageView的圖片
   resetImageViewSource()
   
  }
 }
 
 //手動拖拽滾動開始
 func scrollViewWillBeginDragging(scrollView: UIScrollView) {
  //使自動滾動計(jì)時(shí)器失效(防止用戶手動移動圖片的時(shí)候這邊也在自動滾動)
  //autoScrollTimer?.invalidate()
 }
 
 //手動拖拽滾動結(jié)束
 func scrollViewDidEndDragging(scrollView: UIScrollView,
         willDecelerate decelerate: Bool) {
  //重新啟動自動滾動計(jì)時(shí)器
  //configureAutoScrollTimer()
  
 }
}

如何使用:

var sliderGallery : FullScreenShowImageView!
 var bannerCurrentIndex:Int = 0
 
 //圖片輪播組件協(xié)議方法:獲取內(nèi)部scrollView尺寸
 func galleryScrollerViewSize() -> CGSize {
  return CGSize(width: BWidth, height: BHeight/2)
 }
 
 //圖片輪播組件協(xié)議方法:獲取數(shù)據(jù)集合
 func galleryDataSource() -> [String] {
  return self.bannerView.imageURLStringsGroup as! [String]
 }
 
  //點(diǎn)擊事件響應(yīng)
 func hiddenForCliked(index:Int){
  if(bannerCurrentIndex != index){
    self.bannerView.scrollToIndex(Int32(index))
  }
  self.navigationController?.setNavigationBarHidden(false, animated: false)
 }
 
 func showImageGallery(index:Int){
  //初始化圖片輪播組件
  if(sliderGallery == nil){
   sliderGallery = FullScreenShowImageView(frame: CGRect(x: 0, y: 0, width: BWidth,
    height: BHeight),delegate:self)
   
   sliderGallery.currentIndex = index
   sliderGallery.resetImageViewSource()
   
   //將圖片輪播組件添加到當(dāng)前視圖
   self.view.addSubview(sliderGallery)
   
  }else{
   sliderGallery.currentIndex = index
   sliderGallery.resetImageViewSource()
   sliderGallery.hidden = false
   
  }
  self.sliderGallery.presentViewAnimate()
  self.navigationController?.setNavigationBarHidden(true, animated: false)
 }
 
 //pragma -- SDCycleScrollViewDelegate
 func cycleScrollView(cycleScrollView: SDCycleScrollView!, didSelectItemAtIndex index: Int) {
  print("--------index:\(index)")
  bannerCurrentIndex = index
  self.showImageGallery(index)
  
 }

以上就是本次我們整理的代碼全部內(nèi)容,如果大家學(xué)習(xí)時(shí)候還有任何不明白的地方,可以在下方的留言區(qū)討論,感謝你對腳本之家的支持。

相關(guān)文章

  • Objective C從遠(yuǎn)程url下載圖片方法匯總

    Objective C從遠(yuǎn)程url下載圖片方法匯總

    本文給大家分享了2則使用Objective C從遠(yuǎn)程url下載圖片的方法,都是個(gè)人項(xiàng)目中使用的,匯總下推薦給大家,有需要的小伙伴可以參考下。
    2015-05-05
  • iOS實(shí)現(xiàn)帶遮罩的彈出選項(xiàng)卡

    iOS實(shí)現(xiàn)帶遮罩的彈出選項(xiàng)卡

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)彈出選項(xiàng)卡,并附帶遮罩,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • iOS推送之本地通知UILocalNotification

    iOS推送之本地通知UILocalNotification

    這篇文章主要為大家詳細(xì)介紹了iOS本地通知UILocalNotification,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 詳解iOS 實(shí)現(xiàn)一對多代理方案

    詳解iOS 實(shí)現(xiàn)一對多代理方案

    本文主要介紹了iOS 實(shí)現(xiàn)一對多代理方案,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • iOS自定義UICollectionViewLayout實(shí)現(xiàn)瀑布流布局

    iOS自定義UICollectionViewLayout實(shí)現(xiàn)瀑布流布局

    這篇文章主要為大家詳細(xì)介紹了iOS自定義UICollectionViewLayout實(shí)現(xiàn)瀑布流布局,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • iOS如何封裝帶復(fù)制功能的UILabel示例代碼

    iOS如何封裝帶復(fù)制功能的UILabel示例代碼

    如果是在IOS的應(yīng)用方面,很多時(shí)候我們需要封裝UILabel,下面這篇文章主要給大家介紹了關(guān)于iOS如何封裝帶復(fù)制功能的UILabel的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-08-08
  • Objective-C中的語法糖示例詳解

    Objective-C中的語法糖示例詳解

    開發(fā)過程中我特別喜歡用語法糖,原因很簡單,懶得看到一堆長長的代碼,但語法糖簡單卻不那么簡單,下面這篇文章主要給大家介紹了關(guān)于Objective-C中語法糖的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。
    2018-01-01
  • iOS CoreTelephony 實(shí)現(xiàn)監(jiān)聽通話狀態(tài)

    iOS CoreTelephony 實(shí)現(xiàn)監(jiān)聽通話狀態(tài)

    這篇文章主要介紹了iOS CoreTelephony 實(shí)現(xiàn)監(jiān)聽通話狀態(tài) 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-07-07
  • IOS 貝塞爾曲線(UIBezierPath)屬性、方法整理

    IOS 貝塞爾曲線(UIBezierPath)屬性、方法整理

    這篇文章主要介紹了IOS 貝塞爾曲線(UIBezierPath)屬性、方法的相關(guān)資料,這里整理了貝塞爾 曲線的基礎(chǔ)資料,對屬性及相應(yīng)的方法一一做了詳解,需要的朋友可以參考下
    2016-11-11
  • Reactnative-iOS回調(diào)Javascript的方法

    Reactnative-iOS回調(diào)Javascript的方法

    這篇文章主要介紹了Reactnative-iOS回調(diào)Javascript的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-09-09

最新評論