2016-07-21 13 views
0

collectionViewの画像インデックスを別のviewControllerに送信すると、画像の配列が表示されます。この画像はフルスクリーンで表示され、画像をスワイプする機能がありますが、スワイプの問題は ですそれは非常に高速です私はUIImageViewの時間を遅らせる必要がある画像の間でスワイプ画像がその問題の任意のソリューションを変更したとき?UIImageViewでの遅延時間

以下のコード:のviewDidLoad FUNC

var ImageIndex:Int = 0 // this is index image which i send it from previous view controller 
var arrayOfUrlImageLarge:[String] = []// this array which contain all the url of images 

オーバーライド(){

super.viewDidLoad() 

ImageViewの= UIImageView(画像:UIImage(contentsOfFile:arrayOfUrlImageLarge [ImageIndexプロパティ]))

imageView.contentMode = UIViewContentMode.ScaleAspectFill 

    let swipeGestureRight = UISwipeGestureRecognizer(target: self, action: #selector(ShowImageViewController.swipe(_:))) 
    swipeGestureRight.direction = .Right 
    let swipeGestureLeft = UISwipeGestureRecognizer(target: self, action: #selector(ShowImageViewController.swipe(_:))) 
    swipeGestureLeft.direction = .Left 
    self.imageView.addGestureRecognizer(swipeGestureLeft) 
    self.imageView.addGestureRecognizer(swipeGestureRight) 
} 

funcスワイプ(ジェスチャー:UISwipeGestureRecognizer){

if gesture.direction == .Right { 

     if ImageIndex == 0 { 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     }else { 
      ImageIndex = ImageIndex - 1 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     } 
    } 
    if gesture.direction == .Left{ 

     if ImageIndex >= arrayOfUrlImageLarge.count { 
      ImageIndex = arrayOfUrlImageLarge.count - 1 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     }else { 
      ImageIndex = ImageIndex + 1 
      if ImageIndex >= arrayOfUrlImageLarge.count { 
       return 
      } 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 

     } 
    } 
} 

あなたのスワイプ機能で、このコードを試すことができますか?あなたの

答えて

0
func swipe(gesture:UISwipeGestureRecognizer){ 

    let delay = 4.5 * Double(NSEC_PER_SEC) 
    let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) 
    dispatch_after(time, dispatch_get_main_queue()) { 

     if gesture.direction == .Right { 

     if ImageIndex == 0 { 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     } 
     else { 
      ImageIndex = ImageIndex - 1 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     } 
     } 
     if gesture.direction == .Left{ 

     if ImageIndex >= arrayOfUrlImageLarge.count { 
      ImageIndex = arrayOfUrlImageLarge.count - 1 
      imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     } 
     else { 
     ImageIndex = ImageIndex + 1 
     if ImageIndex >= arrayOfUrlImageLarge.count { 
      return 
     } 
     imageView.image = UIImage(data: NSData(contentsOfFile: arrayOfUrlImageLarge[ImageIndex])!) 
     } 

     } 
    } 
} 
+0

このメソッドをviewdidloadに入れていただきありがとうございますか? –

+0

同じメソッドで試してください –

+0

私はそれを試してみてください –

0

ありがとうございましたかそれが私のためにしたようにあなたのために働くことを願っています。

imageView.image = nil 
UIView.animateWithDuration(0.5, delay: 0.5, options: nil, animations: { 
    // your if-else swipe function for setting up the image on UIImageView 
}, completion: nil) 
関連する問題