我有收集视图并点击其单元格uiview创建时将单元格的坐标转换为superview。接下来,我需要将创建的uiview调整为屏幕尺寸,同时新创建的uiview旋转90度:
let coord = collectionView.layoutAttributesForItem(at: indexPath)
let cellFrameInSuperview:CGRect! = collectionView.convert(coord!.frame, to: self.view)
let imageViewDummy = UIView(frame: CGRect(x: (cellFrameInSuperview?.origin.x)!, y: (cellFrameInSuperview?.origin.y)!, width: cell.videoContainer.coverImageView.frame.size.width, height: cell.videoContainer.coverImageView.frame.size.height))
UIView.animate(withDuration: 3, animations: {
var transform = CGAffineTransform.identity
transform = transform.rotated(by: CGFloat(Double.pi / 2))
imageViewDummy.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.height, height: UIScreen.main.bounds.width)
imageViewDummy.transform = transform
})
但是在动画之后,视图被错误地放置了。它应该适合全屏
更新:
工作代码:
UIView.animate(withDuration: 3, animations: {
imageViewDummy.center = CGPoint(x: imageViewDummy.frame.size.height / 2, y: imageViewDummy.frame.size.width / 2)
var transform = CGAffineTransform.identity
transform = transform.rotated(by: CGFloat(Double.pi / 2))
imageViewDummy.transform = transform
imageViewDummy.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}, completion: {(result: Bool) in
})