我有一个UIViewController视图作为另一个UIViewController视图顶部的子视图/模态,例如子视图/模态应该是透明的,并且任何添加到子视图的组件都应该是可见的.问题是我有子视图显示黑色背景而不是有clearColor.我试图制作UIView一个clearColor而不是黑色背景.有人知道它有什么问题吗?任何建议表示赞赏.
FirstViewController.m
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:NO];
Run Code Online (Sandbox Code Playgroud)
SecondViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.opaque = YES;
self.view.backgroundColor = [UIColor clearColor];
}
Run Code Online (Sandbox Code Playgroud)
决议:我解决了问题.它适用于iPhone和iPad.没有黑色背景的模态视图控制器只是clearColor/transparent.我需要改变的唯一一件事是我换成UIModalPresentationFullScreen了UIModalPresentationCurrentContext.这有多简单啊!
FirstViewController.m
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
注意:如果您使用以下modalPresentationStyle财产navigationController:
FirstViewController.m
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何在Xcode 7(iOS9)上的Swift中解决这个问题,我也遇到了这个错误:
不能下标'[UIViewController]类型的值?' 索引类型为'Int'
任何建议表示赞赏.谢谢.

我的代码:
func indexPositionForCurrentPage(pageViewController: UIPageViewController) -> Int {
let currentViewController = pageViewController.viewControllers[0] as UIViewController
for (index, page) in pages.enumerate() {
if (currentViewController == page) {
return index
}
}
return -1
}
Run Code Online (Sandbox Code Playgroud) 我试图找出如何在Swift中翻译它,我也有这个错误:"无法找到接受提供的参数的"init"的重载".任何建议表示赞赏.谢谢.
var pageImages:[UIImage] = [UIImage]()
pageImages = [UIImage(named: "example.png"), UIImage(named: "example2.png")]
Run Code Online (Sandbox Code Playgroud) 我决定从我的应用程序关闭"提醒"开关控制的通知.我在我的应用程序中添加了这些行,使其支持iOS 7和iOS 8,并且当我关闭推送通知时它正在工作.但是当我决定打开开关并关闭应用程序时,当我再次打开它时它又回到OFF而不是打开.因此,我必须转到设置 - >通知中心 - >"我的应用程序"并重新打开所有内容,因为它们已关闭...非常奇怪,当我在iOS 7上测试时,它正在运行但不适用于iOS 8.任何建议都表示赞赏.谢谢.
- (IBAction)reminderSwitchToggled:(id)sender {
UIApplication *application = [UIApplication sharedApplication];
if ([sender isOn]) {
#ifdef __IPHONE_8_0
if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
else
#endif
{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeSound];
}
} else {
#ifdef __IPHONE_8_0
if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:
(UIUserNotificationType)
(UIUserNotificationTypeNone)
categories:nil]];
[application unregisterForRemoteNotifications];
}
else
#endif
{
[application unregisterForRemoteNotifications];
}
}
}
Run Code Online (Sandbox Code Playgroud) iPad 上 modalPresentationStyle - FormSheet 的高度究竟是多少?我写了一行代码来获取 self.view 的高度,如下所示:
println("Height - modalPresentationStyle FormSheet: \(self.view.frame.size.height)")
Run Code Online (Sandbox Code Playgroud)
经过测试,我得到了这两个结果:
ModalViewController 上没有 Formsheet,高度为1024.0
在 modalPresentationStyle 上使用 Formsheet 时,高度为1024.0 ,这是错误的,因为高度应该小于 1024.0
知道它有什么问题吗?我需要使用表单从 self.view.frame.size.height 中获得正确的高度,因为我需要在代码中的某处编写公式。我不需要更改表单的大小。