7

Khi áp dụng UISplitViewController mới, tôi đang cố thay đổi hành vi mặc định xảy ra khi sử dụng chế độ UISplitViewControllerDisplayModeAutomatic.Ẩn lớp phủ UISplitViewController theo chiều dọc

Khi làm việc theo chiều dọc, tôi muốn lớp phủ chính ẩn khi người dùng kích hoạt tính năng đẩy sang phía chi tiết. Theo mặc định, lớp phủ vẫn còn trên màn hình cho đến khi người dùng chạm vào phía chi tiết.

Tôi đã thử bằng cách sử dụng sau đây với các đại biểu:

- (BOOL)splitViewController:(UISplitViewController *)splitViewController showDetailViewController:(UIViewController *)vc sender:(id)sender 
{ 
    if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { 
     [UIView animateWithDuration:0.3 animations:^{ 
      splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; 
     }]; 
    } 
    return NO; 
} 

này mang lại cho tôi những hành vi mong muốn trong bức chân dung, nhưng điều này phá vỡ chế độ phong cảnh (mà tôi muốn cư xử như UISplitViewControllerDisplayModeAllVisible). Nếu bạn đã thực hiện một cú đẩy và sau đó xoay thiết bị, phía bên trái vẫn bị ẩn (như mong đợi). Tôi không thể tìm thấy một vị trí appriprite để móc vào để thiết lập lại chế độ ưa thích trên xoay để hiển thị phía bên trái (vì bộ sưu tập đặc điểm không thể được sử dụng để nói với cảnh quan vs chân dung trên iPad).

Tôi làm cách nào để kích hoạt loại bỏ lớp phủ theo cách thủ công?

Dupe lưu ý:iOS8 đã thay đổi hoàn toàn UISplitViewController, vì vậy tất cả SO câu trả lời khác trước ngày '14 có lẽ sai (và tôi đã đào qua nhiều trong số họ, chỉ trong trường hợp)

Trả lời

3

Chỉ cần đặt của bạn mã (không có return NO;) trong bộ điều khiển chế độ xem chính prepareForSegue:sender: hoặc tableView:didSelectRowAtIndexPath:. Ở đó nó hoạt động hoàn hảo!

+0

Câu trả lời đơn giản. Tôi tìm thấy thời lượng là 0,3 để có một chút chậm so với hoạt ảnh khi bạn chuyển đổi vào hoặc ra bằng một swipe hoặc nút; 0,2 giây có vẻ đúng. – Nick

+0

Công việc này tuyệt vời nhưng nếu chế độ xem chính hiển thị khi thiết bị được xoay ngang, chế độ xem chi tiết không thay đổi kích thước phù hợp. – Leon

5

Tôi gặp sự cố tương tự như bạn. Tôi đang làm điều này trên nền tảng cảm ứng mono của Xamarin, nhưng tôi nghĩ kết quả sẽ giống nhau.

Giống như những gì LaborEtArs đã nói, hãy di chuyển mã của bạn sang phương thức prepareForSegue:sender: của bộ điều khiển chế độ xem chính. Sau đó, chỉ cần đặt chế độ thành tự động sau khi bạn đặt chế độ thành ẩn:

if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { 
    splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; 
    splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; 
} 

Sau khi thực hiện theo cách này, nó không còn phá vỡ chế độ nằm ngang.

0

Dưới đây là phiên bản Swift:

if (self.splitViewController?.displayMode == UISplitViewControllerDisplayMode.PrimaryOverlay){ 
    splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryHidden 
    splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.Automatic 
} else { 
    println(self.splitViewController?.displayMode) 
} 

Được đặt trong prepareForSegue

-1
@implementation SplitProductView 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.delegate = self; 

} 


- (void)viewWillAppear:(BOOL)animated{ 
    [self resetSplit:[[UIApplication sharedApplication] statusBarOrientation]]; 

    [super viewWillAppear:animated]; 
} 

-(void)resetSplit :(UIInterfaceOrientation)toInterfaceOrientation { 

    //TODOX:iphone 
    if (isPad) 
    { 
     if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){ 
      self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay; 
     } 
     else{ 
      //if (self.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) 
      { 
       self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; 
       self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible; 
       self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; 

      } 
     } 
    } 
} 

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (isPad) 
    { 
     if (!UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])){ 
      self.preferredDisplayMode =UISplitViewControllerDisplayModePrimaryOverlay; 
     } 
    } 

    [self resetSplit:toInterfaceOrientation]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


- (BOOL)splitViewController:(UISplitViewController *)splitViewController 
collapseSecondaryViewController:(UIViewController *)secondaryViewController 
    ontoPrimaryViewController:(UIViewController *)primaryViewController { 
    return YES; 
} 
1

Bên cạnh những lời khuyên từ LaborEtArs để làm hoạt hình của bạn trong prepareForSegue:sender: hoặc tableView:didSelectRowAtIndexPath:, nếu ứng dụng của bạn thường có splitViewController:preferredDisplayMode đặt thành UISplitViewControllerDisplayModeAutomatic, chỉ cần sử dụng phương thức animateWithDuration: với trình xử lý hoàn tất để khôi phục displayMode sau hoạt ảnh:

if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { 
    [UIView animateWithDuration:0.3 animations:^{ 
     splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; 
    } completion:^(BOOL finished){ 
     splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; 
    }]; 
} 
+0

Hoạt ảnh thực sự quan trọng để thực hiện điều này. Thanh danh. Tuy nhiên, việc đặt điều này trong 'didSelectRowAtIndexPath' sẽ gây ra một hoạt cảnh xem chi tiết kỳ lạ (không mong muốn). Đặt nó trong 'PrepareForSegue: kết quả của người gửi' trong một hình ảnh động rực rỡ. – David

Các vấn đề liên quan