MFMailComposeViewController 以横向模式打开时出现黑屏
当手机处于 UIInterfaceOrientationPortrait 时,使用 MFMailComposeViewController 工作正常,但是如果我不允许自动旋转,当用户旋转手机时,我会得到类似的结果:
所以我决定允许视图控制器(这也是一个模态视图),它是调用模态视图进行旋转的视图的一部分:
RootAppInfoViewController.h
#import <UIKit/UIKit.h>
@interface RootAppInfoViewController : UIViewController <UINavigationControllerDelegate>{
UINavigationController *navigationControl;
}
@property (nonatomic,retain) IBOutlet UINavigationController *navigationControl;
//dismisses this modal view
- (IBAction)selectHome:(id)sender;
@end
RootAppInfoViewController.m
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
(顺便说一句,拥有此自动旋转功能可以旋转整个视图)。但这只是一个视图控制器,我希望以模态方式呈现表格视图,因此我有这个类,它通过 RootAppInfoViewController.xib 引用,这使得该模态视图成为表格视图:
AppInfoViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface AppInfoViewController : UITableViewController <MFMailComposeViewControllerDelegate, UINavigationControllerDelegate> {
NSMutableArray *dataSourceArray;
}
@property(nonatomic, retain) NSMutableArray *dataSourceArray;
@end
AppInfoViewController.m
//..
/* //NOTE: Commenting or uncommenting this block of code has no effect!
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}//*/
//...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *source = [[[self.dataSourceArray objectAtIndex:indexPath.section] objectForKey:kSourceKey] objectAtIndex:indexPath.row];
if(indexPath.section == kFeedbackSection) {
if([MFMailComposeViewController canSendMail]) {
// fill out email
//...
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
//MailCompose *controller = [[MailCompose alloc] init];
controller.mailComposeDelegate = self;
[[controller navigationBar] setTintColor:[UIColor oceanColor]];
[controller setToRecipients:[NSArray arrayWithObject:kFeedbackEmail]];
[controller setSubject:emailSubject];
[controller setMessageBody:emailBodyTemplate isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
} else {
[UIAlertHelper mailErrorAlert];
}
} //...
}
#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate methods
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
注释或非注释注释掉此类中的自动旋转代码没有任何效果。保持设备直立并单击加载 MFMailComposeViewController 的行不会有任何问题,它会直立加载,然后旋转得很好。但是,加载表格视图,将其侧向放置,然后使用 MFMailComposeViewController 点击该行,会将模式视图控制器加载为空白屏幕:
这种情况在模拟器和实际物理设备中都会发生。
有人知道怎么回事吗?提前致谢!
Using MFMailComposeViewController works fine when the phone is in UIInterfaceOrientationPortrait, however If I do not allow autorotation I get something like this when the user rotates the phone:
So I decided to allow the view controller (which is also a modal view), that is a part of the view that calls the modal view to rotate:
RootAppInfoViewController.h
#import <UIKit/UIKit.h>
@interface RootAppInfoViewController : UIViewController <UINavigationControllerDelegate>{
UINavigationController *navigationControl;
}
@property (nonatomic,retain) IBOutlet UINavigationController *navigationControl;
//dismisses this modal view
- (IBAction)selectHome:(id)sender;
@end
RootAppInfoViewController.m
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
(Having this autorotate allows rotation for this entire view by the way). But this is a mere view controller and I want a table view to be presented modally so I have this class, which is referenced through the RootAppInfoViewController.xib which makes this modal view a table view:
AppInfoViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface AppInfoViewController : UITableViewController <MFMailComposeViewControllerDelegate, UINavigationControllerDelegate> {
NSMutableArray *dataSourceArray;
}
@property(nonatomic, retain) NSMutableArray *dataSourceArray;
@end
AppInfoViewController.m
//..
/* //NOTE: Commenting or uncommenting this block of code has no effect!
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}//*/
//...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *source = [[[self.dataSourceArray objectAtIndex:indexPath.section] objectForKey:kSourceKey] objectAtIndex:indexPath.row];
if(indexPath.section == kFeedbackSection) {
if([MFMailComposeViewController canSendMail]) {
// fill out email
//...
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
//MailCompose *controller = [[MailCompose alloc] init];
controller.mailComposeDelegate = self;
[[controller navigationBar] setTintColor:[UIColor oceanColor]];
[controller setToRecipients:[NSArray arrayWithObject:kFeedbackEmail]];
[controller setSubject:emailSubject];
[controller setMessageBody:emailBodyTemplate isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
} else {
[UIAlertHelper mailErrorAlert];
}
} //...
}
#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate methods
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
Commenting or non-commenting out the autorotation code in this class has no effect. holding the device upright and clicking on the row that loads the MFMailComposeViewControlleryeilds no problems, it loads upright, then it rotates just fine. However, loading the table view, holding it sideways and then tapping on the row with the MFMailComposeViewController loads the modal view controller as a blank screen:
This happens both in the simulator and the actual physical device.
Anyone know what's up? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了充分解释答案,我必须首先详细说明我的模态视图是如何创建的。
以下是我的观点概述:
RootViewController -> AppInfoViewController-> MFMailComposeViewController
我在 RootViewController 中有以下方法:
它将弹出一个模式视图控制器,显示一个表视图,用户可以从中深入到其他视图。这里的问题是,我创建了模态控制器,而没有将它首先呈现的视图放入导航控制器中,如下所示:
将我的代码更改为上面的代码后,一切正常。问题不在 AppInfoViewController 中。
In order to adequately explain the answer, I must first elaborate on how my modal view was created.
Here is an overview of my views:
RootViewController -> AppInfoViewController -> MFMailComposeViewController
I had in my RootViewController the following method:
Which would pop up a modal view controller displaying a table view from which the user will be able to drill down into other views. The problem here is that I created the modal controller without placing the view it first presents into a navigation controller, like so:
After changing my code to the above, everything worked fine. The problem wasn't in AppInfoViewController.