사용자 정의 애니메이션의 toView 객체의 프레임, 나는 "폴더"의 최종 위치의 프레임 알고있다 방법 : 난 액세스 나 iOS의 홈 화면 폴더와 같은 애니메이션을 만들고 싶어
을
class FolderAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
let duration = 5.0
var presenting = true
func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(_ transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView()
let toViewC = transitionContext.viewController(forKey: UITransitionContextToViewControllerKey)! as! ProjectViewController
let fromViewC = transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey)!as! ViewController
let cell : FolderCollectionViewCell = fromViewC.folderCollectionView.cellForItem(at: (fromViewC.folderCollectionView.indexPathsForSelectedItems()?.first!)!) as! FolderCollectionViewCell
let cellSnapshot: UIView = cell.snapshotView(afterScreenUpdates: false)!
let cellFrame = containerView.convert(cell.frame, from: cell.superview)
cellSnapshot.frame = cellFrame
cell.isHidden = true
toViewC.view.frame = transitionContext.finalFrame(for: toViewC)
toViewC.view.alpha = 0
containerView.addSubview(toViewC.view)
containerView.addSubview(cellSnapshot)
UIView.animate(withDuration: duration, animations: {
toViewC.view.alpha = 1.0
let finalFrame = containerView.convert(toViewC.containerView.frame, from: toViewC.view)
cellSnapshot.frame = finalFrame
}) { (_) in
cellSnapshot.removeFromSuperview()
transitionContext.completeTransition(true)
}
}
}
모든 (A CGRect 변수입니다) finalFrame
값을 설정 let finalFrame = containerView.convert(toViewC.containerView.frame, from: toViewC.view)
제외하고는 제대로 작동 (origin = (x = 0, y = 0), size = (width = 0, height = 0))
에 : 여기에 사용자 전환을 사용하면 애니메이션 파일의 코드입니다.
나는 어떻게 올바르게 속성에 액세스 할 수 있습니다, 그래서
스위프트
내 코드를 작성, this 튜토리얼을 따라 한?
스크린 샷을 볼 수있는 것처럼 'toViewC.containerView.frame'에 액세스하려고합니다. 즉, "폴더"의 rect입니다. 전환을 제거했지만 작동하지 않습니다 ... – ale00
오, 죄송합니다! 나는 잘못 읽었다. 잠시만 기다려주세요. 내 대답을 편집 할게요 – jrturton
하지만'completeTransition'에'false'를 보내면 첫 번째보기로 돌아갑니다. – ale00