2017-07-30 4 views
0

私は2つのメインビューで構成される天気予報を作成しています。 最初のビューはメインビューで、スクロール可能なUICollectionViewがあり、小さな天気カードを表すセルがあります。 2番目のビューは、より詳細に表示されたすべての天気詳細を持つ異なるビューです。UIViewを作成し、それを画面いっぱいに拡大します

コレクションビューの上にUIViewを作成し、それを拡大して画面いっぱいにしたいと考えています。悲しいことに、私は失敗し続け、それを行う適切な方法を見つけることができません。 セルを押したときに、セルの上にUIViewを作成して(ビュー上の位置を取得する)、画面を拡大するためにUIViewを作成します。私はコードを置くつもり

This is the main view.

:今

let theAttributes:UICollectionViewLayoutAttributes! = collectionView.layoutAttributesForItem(at: indexPath) 
    let cellFrameInSuperview:CGRect! = collectionView.convert(theAttributes.frame, to: collectionView.superview) 

作成するのと同じフレームのUIViewの:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    print("Cell [\(indexPath.row)] selected.") 

    // Get cell position on screen: 
    let attributes = collectionView.layoutAttributesForItem(at: indexPath) 
    let cellRect = attributes?.frame 
    let frameCellInSuperview = collectionView.convert(cellRect!, to: collectionView.superview) 
    print("x: \(Double(frameCellInSuperview.origin.x)), y: \(Double(frameCellInSuperview.origin.y))") 

    // Create a small UIView in the exact same position 


    // Grow the UIView to fill the screen 
} 

答えて

0

を、あなたは、このコードを使用して、スーパーに対して、現在のインデックスのフレームを取得することができます。このコードを使用する:

var popView = UIView(frame: cellFrameInSuperview) 
self.view.addSubview(popView) 

は、今のフレームを更新することでビューをアニメーション化:

UIView.animateWithDuration(3.0, animations: { 
     popView.frame = UIScreen.main.bounds 
    }) 
関連する問題