2016-04-19 13 views
0

私は約12枚の画像を持つCollectionViewを持っています。画像をタップすると、その画像が次の画面に表示されます。問題は、特定の画像をタップすると表示された後、11枚の画像の残りの部分をアニメーション化する必要があることです。それをどうやってやりますか?私は画像の配列をアニメーション化するコードを持っていますが、私はタップした特定の画像をどのように表示するのかわからないので、配列を通してアニメーションを開始します。イメージの配列を別のビューに渡すにはどうすればいいですか?

ここに私のサンプルコードです!

func convertUrlsToImage() { 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { 
     for urls in self.arrayOfImageUrlsFromOtherView { 
      if let url = NSURL(string: urls) { 
       if let data = NSData(contentsOfURL: url) { 
        if let hingeImage = UIImage(data: data) { 
         self.convertedURLToImages.append(hingeImage) 

         dispatch_async(dispatch_get_main_queue(), { 
          if self.galleryImageView.image == nil { 
           self.galleryImageView.image = self.convertedURLToImages[0] 
          }else{ 
           print("Not empty") 
          } 
         }) 
        } 
       } 
      } 
     } 
    }) 
} 

func animateThroughArrayOfImages() { 
    let currentIndex = convertedURLToImages.indexOf(galleryImageView.image!) 
    let nextIndex = (currentIndex! + 1) % self.convertedURLToImages.count 

    self.title = "\(nextIndex+1)" + "/\(convertedURLToImages.count)" 
    self.galleryImageView.image = self.convertedURLToImages[nextIndex] 
} 

//あなたの仕事は非常に単純に見える

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 

    if let cell = collectionView.cellForItemAtIndexPath(indexPath) { 

     performSegueWithIdentifier("nextView", sender: cell) 

    }else{ 
     print("no good") 
    } 
} 







override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 





    if let indexPath = self.collectionView?.indexPathForCell(sender as! ImageCollectionViewCell) { 

     if segue.identifier == "nextView" { 

      let galleryViewController = segue.destinationViewController as! GalleryViewController 


      //We are passing the url to the next screen then making another request to show them 
      let imageUrl = hingeImagesArray[indexPath.row] 


      //passesd a single image url 
      galleryViewController.imageUrlFromOtherScreen = imageUrl.imageUrl 






      //Pasing array of urls 
      galleryViewController.arrayOfImageUrlsFromOtherView = hingeImageUrls 

      //let myIndex = testImageArray[indexPath.row] 








     } 


    } 

} 

答えて

0

追加コード。ただ、collectionView

optional func collectionView(_ collectionView: UICollectionView, 
didSelectItemAtIndexPath indexPath: NSIndexPath) 

ために、このデリゲートを実装次にindexPathからあなたのイメージのインデックスを取得します。次に、このインデックスをurls配列と一緒に次の画面に渡して、それを使って初期画像を設定することができます。

しかし、いずれにしても、すべてのイメージを1つのメモリ内アレイに保存することはお勧めできません。

+0

それは助けがありますが、私はそのバスをまだ混乱させたと思います。私が追加した追加のコードを見て、どうすればいいのか教えてください!誰かがタップしたcollectionViewセルに基づいて初期イメージを設定し、残りの配列を循環させる必要があります。私のコードでは、常に配列self.galleryImageView.image = self.convertedURLToImages [0]の最初のセルイメージに設定されています。私は静的なインデックスの代わりにユーザーがタップした画像にする方法を知らない! – SteveSmith

+0

'galleryViewController'に' preparedForSegue'で設定できる 'selectedIndex'プロパティを与えて、それをアニメーションの開始点として使うのはなぜでしょうか?追加のコードのあなたの最後のコメントは、ほとんどそれをやっているようです。 – sgib

+0

@sgib私に例(コード)を教えてもらえますか?私はそれを前にしたことはありません。ありがとうございます – SteveSmith

関連する問題