2012-05-22 32 views
5

Tôi đã thiết lập hai bộ điều khiển chế độ xem trong Bảng phân cảnh, mỗi nút có nút tác vụ. Tôi thiết lập hai phân đoạn:Hướng lật ngang trong Bảng phân cảnh iOS

  1. Từ bộ điều khiển xem đầu tiên tới bộ điều khiển chế độ xem thứ hai: Phương thức, Lật ngang.
  2. Từ bộ điều khiển chế độ xem thứ hai cho bộ điều khiển chế độ xem đầu tiên: Phương thức, Lật ngang.

Mọi thứ đều hoạt động, nhưng tôi muốn lật ngược một chiều và quay lại, giờ đây nó sẽ chuyển sang cùng một hướng cho cả hai bộ điều khiển chế độ xem.

Cách dễ nhất để tạo hiệu ứng lật ngược lại là gì?

Trả lời

6

Tôi gặp phải vấn đề tương tự và hy vọng tìm được giải pháp.

Tôi đã sử dụng phân đoạn tùy chỉnh để lật ngược lại. Đây là mã của FlipLeftSegue

@implementation FlipLeftSegue 
- (void)perform 
{ 
    UIViewController *src = (UIViewController *) self.sourceViewController; 
    UIViewController *dst = (UIViewController *) self.destinationViewController;  

    [UIView beginAnimations:@"LeftFlip" context:nil]; 
    [UIView setAnimationDuration:0.8]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:src.view.superview cache:YES]; 
    [UIView commitAnimations]; 

    [src presentViewController:dst animated:NO completion:nil]; 
} 
@end 

Vấn đề duy nhất của tôi, tôi tìm thấy giải pháp này, đó là phương pháp được gọi là viewDidAppear immediatly khi các hình ảnh động khởi động. Trong khi với segue bình thường, nó được gọi là sau khi hoạt hình.

+0

Điều này là do bạn đang phanh hệ thống phân cấp view controller. Sử dụng chuyển đổi UIViewcontrollerViewViewController: ... – doozMen

5

Thay vì tạo bản trình bày mới của ViewController, tôi khuyên bạn nên truy cập thuộc tính cho presentingViewController trên ViewController thứ hai và sau đó gọi -dismissViewControllerAnimated: completion: trên đó. Cũng giống như vậy:

-(IBAction)someResponderToYourCancelButtonOrWhatever:(id)sender { 
    // Do some stuff 
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 
} 
+0

Đây phải là câu trả lời được chấp nhận ... –

1

Bạn tốt hơn sử dụng mã này trong câu trả lời của NSZombie:

- (void)swapChildVCFrom:(UIViewController *)from to:(UIViewController *)to options:(enum UIViewAnimationOptions)options 
{ 
    [self addChildViewController:to]; 
    [from willMoveToParentViewController:nil]; 

    // Adjust the new child view controller's view's frame 
    // For example here just set it to fill the parent view 
    to.view.frame = self.view.bounds; 

    [self transitionFromViewController:from 
         toViewController:to 
           duration:1.0 
           options:options 
          animations:nil 
          completion:^(BOOL b) 
          { 
           [to didMoveToParentViewController:self]; 
           [from.view removeFromSuperview]; 
           [from removeFromParentViewController]; 
          }]; 
} 
Các vấn đề liên quan