0
我正在用自定義的presentationStyle呈現一個viewcontroller。父控制器是一個UICollectionViewController。在我的UICollectionViewController的didSelectAtIndexPath方法中,我選取了所選單元格的UIImageView並將其動畫化爲模態呈現的視圖控制器內的UIView框架的位置。如何獲取UIView在模態呈現viewController的位置
我怎樣才能得到UIView的模態呈現視圖控制器的框架?
self.imageView!.frame = trophyOverlayVC.trophyImageLocationView!.frame
不起作用。
它在大多數情況下出現在屏幕外。
import UIKit
class CollectionHolderViewController: MainPageContentViewController, UICollectionViewDelegate, UICollectionViewDataSource {
[..insert other methods here..]
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionCell", forIndexPath: indexPath) as TrophyCollectionViewCell
self.collectionViewController.collectionView!.scrollEnabled = false // disable scrolling so view won't move
self.collectionViewController.collectionView!.userInteractionEnabled = false
let innerOffset = collectionView.contentOffset as CGPoint // offset of content view due to scrolling
let attributes = self.collectionViewController.collectionView!.layoutAttributesForItemAtIndexPath(indexPath) as UICollectionViewLayoutAttributes!
let cellRect = attributes.frame // frame of cell in contentView
imageView = UIImageView(frame: CGRectMake(cellRect.origin.x, cellRect.origin.y, cellRect.size.width, cellRect.size.height)) //places image in location of collectionViewCell.
imageView!.image = UIImage(named: placeHolderArray[indexPath.row]) //change.
imageView!.contentMode = UIViewContentMode.ScaleAspectFit
self.collectionViewController.collectionView!.addSubview(imageView!)
self.placeHolderArray[indexPath.row] = ""
UIView.setAnimationsEnabled(false)
self.collectionViewController.collectionView!.reloadItemsAtIndexPaths([indexPath])
UIView.setAnimationsEnabled(true)
var trophyOverlayVC = self.collectionViewController.storyboard!.instantiateViewControllerWithIdentifier("TrophyOverlayVC") as TrophyOverlayViewController
trophyOverlayVC.modalPresentationStyle = UIModalPresentationStyle.Custom
self.presentViewController(trophyOverlayVC, animated: false, completion: self.presentViewController(trophyOverlayVC, animated: false, completion: { (value: Void) in UIView.animateWithDuration(0.5, animations: {
self.imageView!.frame = trophyOverlayVC.trophyImageLocationView!.frame
}, completion: {
(value: Bool) in
}) })
}
好吧,所以我現在有動畫發生在完成塊。這並沒有解決問題,所以我想我需要使用convertRect。 – CaptainCOOLGUY 2014-12-19 00:18:21
任何人都可以使用我發佈的代碼提供示例嗎? – CaptainCOOLGUY 2014-12-19 00:40:35