Tôi muốn sử dụng tùy chọn UIViewAnimationOptionShowHideTransitionViews, cho phép cả toView và fromView ở trong phân cấp khung nhìn trước khi chuyển đổi, nhưng hiển thị một và ẩn khác.
Đặt thànhView để ẩn, thêm nó vào superview và cài đặt các ràng buộc trước khi chuyển đổi. Sau đó, bạn có thể xóa chế độ xem cũ trong khối hoàn thành. Một cái gì đó như thế này:
[toView setHidden: YES];
[containerView addSubview: toView];
[containerView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @"|[toView]|" options: 0 metrics: nil views: NSDictionaryOfVariableBindings(containerView, toView)]];
[containerView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|[toView]|" options: 0 metrics: nil views: NSDictionaryOfVariableBindings(containerView, toView)]];
[UIView transitionFromView: fromView toView: toView duration: 1.0 options: UIViewAnimationOptionTransitionFlipFromBottom | UIViewAnimationOptionShowHideTransitionViews completion:^(BOOL finished) {
[fromView removeFromSuperview];
}];
Nguồn
2012-12-14 23:58:16
.. Từ những gì tôi thấy, fromView bị xóa khỏi superview tự động ngay cả khi hiển thị/ẩn tùy chọn được sử dụng – Andy
Nhìn vào hệ thống phân cấp khung nhìn sau cuộc gọi, fromView là defiantly không bị loại bỏ khỏi superview (ít nhất là trên iOS 6 và iOS 7) – honus
để sử dụng hoạt ảnh lật với ràng buộc AutoLayout, chúng tôi phải đặt 'UIViewAnimationOptionShowHideTransitionViews' –