UIModalPresentationPageSheet의 구석에 버튼을 추가하는 방법이 있습니까? 내 말은, Apple과 같은 (x) 버튼을 페이지 시트의 모서리에 놓고 싶지만 부모보기에 추가하면 페이지 시트 뒤에 표시되고 (또한 탭할 수 없음) 페이지에 추가됩니다 시트는보기 영역 밖에 있기 때문에 숨겨진 부분을 숨 깁니다.UIModalPresentationPageSheet 코너에 닫기 버튼 추가
해결책이 있습니까?
감사합니다.
UIModalPresentationPageSheet의 구석에 버튼을 추가하는 방법이 있습니까? 내 말은, Apple과 같은 (x) 버튼을 페이지 시트의 모서리에 놓고 싶지만 부모보기에 추가하면 페이지 시트 뒤에 표시되고 (또한 탭할 수 없음) 페이지에 추가됩니다 시트는보기 영역 밖에 있기 때문에 숨겨진 부분을 숨 깁니다.UIModalPresentationPageSheet 코너에 닫기 버튼 추가
해결책이 있습니까?
감사합니다.
다음은 내가 사용하는 해결책입니다. 그것은 당신이 묘사하는 것과는 너무 깔끔하지는 않지만 버튼이 부분적으로 뷰의 경계 밖으로 나가기를 원하기 때문에 까다로울 것입니다 (말하자면 뷰 컨트롤러의 자식이어야합니다. 보기의 수퍼 뷰).
내 솔루션은 탐색 모음의 왼쪽 버튼 영역에 닫기 버튼을 넣는 것입니다. 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
편집 : 사실, 내가 제안하는 첫 번째 것은 다른 종류의 닫기 버튼을 사용하는 것입니다. 예를 들어 상단에 도구 모음을 Done
버튼과 함께 추가 할 수 있습니다.
여전히 Apple 스타일의 플로팅 X가 필요한 경우 속성을 설정하여 숨기거나 잘리지 않는지 확인하십시오. 더 좋은 방법은 스타일이 지정된 단추 이미지 인 전경 이미지와 페이지 시트의 배경색/패턴을 단추 주변의 투명한 배경으로 페이드하는 배경 이미지를 사용하여 UIButton
을 만드는 것입니다. 페이지 시트 경계를 벗어나지 않고도 효과적으로 "닫기 버튼"을 제공합니다.
clipsToBounds는 페이지 시트의 범위를 벗어나 확장 할 수 없으므로 페이지 시트 내부에 표시된보기에는 영향을 미치지 않습니다. –
@ TomSwift의 제안이 매우 유용합니다. 다음은 비추천 API가 아닌 iOS7 메소드와 ARC를 사용하는 버전입니다.
@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];
[nc setToolbarHidden:YES animated: NO];
nc.modalPresentationStyle = modalViewController.modalPresentationStyle;
modalViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:onDismiss];
}
else
{
nc = (UINavigationController*) modalViewController;
UIViewController* rootViewController = [nc.viewControllers objectAtIndex: 0];
rootViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:onDismiss];
}
[nc setNavigationBarHidden: NO];
nc.navigationBar.barStyle = UIBarStyleBlack;
nc.toolbar.barStyle = self.navigationController.navigationBar.barStyle;
[self presentViewController:nc animated:animated completion:nil];
}
- (void)presentAutoModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
{
[self presentAutoModalViewController:modalViewController withDismissAction: @selector(autoModalViewControllerDismiss:) animated: animated];
}
- (void)autoModalViewControllerDismiss: (id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)isAutoModalViewController
{
return (self.navigationController != nil && self.navigationController.parentViewController != nil && self.navigationController.parentViewController.presentedViewController == self.navigationController);
}
@end
그리고 내가 좋아하는 호출 ...
MyController *vc = [[MyController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentAutoModalViewController:info animated:YES];
당신이 "이보기 영역에서이기 때문에, 그것의 일부 숨겨진 만들 것 페이지 시트에 추가."무엇을 의미합니까? –