Đây là giải pháp tôi sử dụng. Nó không hoàn toàn là những gì bạn mô tả, cũng sẽ gọn gàng, nhưng sẽ rất khó vì bạn muốn nút nằm ngoài phần giới hạn của khung nhìn (như bạn nói, nó sẽ là con của view-controller- giám sát của view).
Giải pháp của tôi là đặt nút đóng ở khu vực nút bên trái của thanh điều hướng. Tôi làm điều này automagically thông qua một phần mở rộng lớp UIViewController. Để sử dụng nó, chỉ cần gọi [currentViewController presentAutoModalViewController: modalViewController animated: YES];
@implementation UIViewController (Modal)
- (void) presentAutoModalViewController: (UIViewController *) modalViewController withDismissAction: (SEL) onDismiss animated:(BOOL)animated
{
UINavigationController* nc = nil;
if (NO == [ modalViewController isKindOfClass: [UINavigationController class]])
{
nc = [[[UINavigationController alloc] initWithRootViewController: modalViewController] autorelease];
[nc setToolbarHidden:YES animated: NO];
nc.modalPresentationStyle = modalViewController.modalPresentationStyle;
modalViewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:onDismiss] autorelease];
}
else
{
nc = (UINavigationController*) modalViewController;
UIViewController* rootViewController = [nc.viewControllers objectAtIndex: 0];
rootViewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:onDismiss] autorelease];
}
[nc setNavigationBarHidden: NO];
nc.navigationBar.barStyle = UIBarStyleBlack;
nc.toolbar.barStyle = self.navigationController.navigationBar.barStyle;
[self presentModalViewController: nc animated: animated ];
}
- (void) presentAutoModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
{
[self presentAutoModalViewController:modalViewController withDismissAction: @selector(autoModalViewControllerDismiss:) animated: animated];
}
- (void) autoModalViewControllerDismiss: (id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL) isAutoModalViewController
{
return (self.navigationController != nil && self.navigationController.parentViewController != nil && self.navigationController.parentViewController.modalViewController == self.navigationController);
}
@end
Ý anh là gì bởi "thêm nó vào trang Sheet sẽ làm cho một phần của nó ẩn, vì nó ra khỏi khu vực xem."? –