Вот решение, которое я использую.Это не совсем то, что вы описываете, что тоже было бы аккуратно, но было бы сложно, так как вы бы хотели, чтобы кнопка частично выходила за границы представления (как вы говорите, она должна быть дочерней по отношению к контроллеру представления -просмотр суперпредставления).
Мое решение - поместить кнопку закрытия в область левой кнопки навигационной панели.Я делаю это автоматически с помощью расширения класса UIViewController.Чтобы использовать его, просто вызовите [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