我没有找到将半透明效果(iOS 7)移除到MFMailComposeViewController的UINavigationBar的方法。我的应用程序中的所有其他UINavigationBars都没问题。
我尝试了这个没有成功:
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.navigationBar.translucent = NO;
有什么想法吗?
答案 0 :(得分:1)
有点晚了,但对于遇到这篇文章的人来说:
默认情况下,MFMailComposeViewController的navigationBar将是半透明的,您无法更改它。您可以更改的唯一属性是Appearance Proxy支持的属性。来自Apple文档:
此类的视图层次结构是私有的,您不能修改 它。但是,您可以使用自定义实例的外观 UIAppearance协议。
这使您无法选择更改MFMailComposeViewController的导航栏外观,因为并非所有属性都受支持(例如,如果您尝试类似[UINavigationBar外观] setTranslucent:NO];它会崩溃,因为此属性不受支持代理人。
以下是Appearance代理支持的属性列表:https://gist.github.com/mattt/5135521
现在,要将MFMailComposeViewController的navigationBar设置为非半透明,您需要更改其backgroundColor(它是UIView允许的属性,UINavigationBar是UIView的子类):
[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
确保在实例化MFMailComposeViewController之前执行此操作,例如:
[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
你也可以使用appearanceWhenContainedIn:MFMailComposeViewController,只有当它被MFMailComposeViewController拥有时才会影响navBar,或者你可以选择将它改回到之前在mailComposeController中的任何东西:didFinishWithResult。
答案 1 :(得分:0)
我想我在某处读过Apple不希望我们对ViewController进行多次定制,但除此之外,此处接受的SO anser可能有所帮助:MFMailComposeViewController in iOS 7 statusbar are black
...因为时间问题。
答案 2 :(得分:0)
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
[self.navigationController presentViewController:mailVC animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];
如果不想让它在全球范围内改变:
尝试将类别添加到MFMailComposeViewController
@implementation MFMailComposeViewController (IOS7_StatusBarStyle)
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
-(UIViewController *)childViewControllerForStatusBarStyle
{
return nil;
}
@end
答案 3 :(得分:0)
这不适用于几行代码,但这是一种可能适合您的方法。
隐藏导航栏:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
要表明:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
此处提供了此方法的文档。
要监听“双击”或双击子类UIView,并将该子类的实例作为视图控制器的视图属性。
在视图子类中,覆盖其-touchesEnded:withEvent:方法,并计算在一段时间内获得的触摸次数,方法是测量两次连续点击之间的时间,可能使用-timeIntervalSinceDate:。或者从[touch tapCount]测试结果。
如果您获得两次点击,您的子视图会发出视图控制器已注册要侦听的NSNotification。
当您的视图控制器听到通知时,它会触发一个选择器,该选择器使用上述代码隐藏或显示导航栏,具体取决于导航栏的当前可见状态,通过读取导航栏的isHidden属性进行访问。