1

デモのようなトランジションアニメーションをhereのように作成しようとしています。だから、私がセルをクリックすると、画面全体が拡大して表示されます。ここでタップ時にUICollectionViewとそのセルを展開する

は私のコードは、だから私は使用思っ `

import UIKit 

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 

@IBOutlet weak var mainDesLabel: UILabel! 
@IBOutlet weak var collectionView: UICollectionView! 
@IBOutlet weak var secDesLabel: UILabel! 
let searchBar = UISearchBar() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    self.collectionView.delegate = self 
    self.collectionView.dataSource = self 
    self.collectionView.backgroundColor = UIColor.clearColor() 
    //////////////////////////////////////////////////////////////////////// 
    self.searchBar.frame = CGRect(x: 175, y: 0, width: 200, height: 50) 
    self.searchBar.searchBarStyle = UISearchBarStyle.Minimal 
    self.searchBar.backgroundColor = UIColor.whiteColor() 
    self.view.addSubview(searchBar) 
    //////////////////////////////////////////////////////////////////////// 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return 10 
} 

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell 

    cell.layer.cornerRadius = 5 

    return cell 
} 



func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
    return 1 
} 

//Use for size 
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 
    self.collectionView.frame = self.view.bounds 
    let cell = collectionView.cellForItemAtIndexPath(indexPath) 
    cell!.frame = CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height) 
} 


} 

(私はCollectionViewに慣れていないだということを認めなければならない)されている「didSelectItemAtIndexPath」役立つだろう、しかし、それはthis

の考えのように判明します?どんな助けも高く評価されるでしょう!

+0

https://www.raywenderlich。com/113845/ios-animation-tutorial-custom-view-controller-presentation-transitions – HMHero

答えて

2

あなただけUICollectionViewは、ビューのレイアウトを実行し終わったらUICollectionViewCellのサイズを更新するためにdidSelectItemAtIndexPathまたは任意の類似の方法を使用することはできません。

セルの高さを更新するには、 didSelectItemAtIndexPathでタップされたセルを最初に取得できます。 次に、新しいセルフレームをsizeForItemAtIndexpathに渡してコレクションビュー全体を再ロードするか、 または、特定のセルをreloadItemsAtIndexPathsでリロードすることはできますが、それでもsizeForItemAtIndexpath経由でセルの更新サイズを渡す必要があります。

更新日 質問の詳細は、必要なアニメーションによって更新されています。 didSelectItemAtIndexPathにタップされていたセルをキャプチャ

  1. - :

    は私がで同様のアニメーションを行っていました。

  2. UIViewContrllerにレプリカビューを追加しますが、そのフレームはタップされたセルと完全に一致します。
  3. 次に、追加されたビューをアニメーション化します。したがって、細胞がアニメーション化されたという印象を与える。

このビューでは、追加の機能を記述することもできます。したがって、セルのコードとアニメーション表示も分離されています。

+0

Thx、これを達成する方法を私に教えてくれます。あなたはそのための例がありますか?私はいくつかのステップと混同しています。 –

+0

たとえば、私はセルを同時にカバーするuiviewを入れようとしますが、セルに追加されました。 –

+0

UICollectionViewLayoutAttributes * attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath];次に、attributes.frameを使用して、セルのフレームを取得できます。これで、このフレームを使用してノートビューコントローラーにレプリカビューを配置する必要があります。 (注:viewcontroller、notcellまたはcollectionview) – 7vikram7

1

または、項目を展開してフレームをUIAnimationで変更することができます。

セルをタップすると、セル内のビューも自動レイアウトを使用して展開され、(クリップの境界に向かって)ヒントが得られます。このような

何か:

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

    let item = collectionView.cellForItemAtIndexPath(indexPath) as! cellCollectionViewExpress // or whatever you collection view cell class name is. 

    UIView.animateWithDuration(1.0, animations: { 
     self.view.bringSubviewToFront(collectionView) 
     collectionView.bringSubviewToFront(item) 
     item.frame.origin = self.view.frame.origin /// this view origin will be at the top of the scroll content, you'll have to figure this out 
     item.frame.size.width = self.view.frame.width 
     item.frame.size.height = self.view.frame.height 
    }) 
} 

物事はそれを使用してと、一般的に安心しているので、私は、あなたがUICollectionViewコントローラを使用することをお勧めします。

関連する問題