私のアプリケーションは横向きmodにあります。現在のモデルビューからMFMailComposeViewControllerを呼び出すと、横向きmodになります。デバイスを回転し、MFMailComposeViewControllerビューが縦向きmodになります。この回転を制限したいのですが、常に横向きmodのみにする必要があります。それを行う方法..
4 に答える
MFMailComposeViewController クラスをサブクラス化して、shouldAutorotateToInterfaceOrientation をオーバーライドして好きなように表示できるようにします。
@interface MailCompose : MFMailComposeViewController {
}
@end
@implementation MailCompose
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
@end
MFMailComposeViewController の代わりに新しいクラスを指定します。
MailCompose *controller = [[MailCompose alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"In app email..."];
[controller setMessageBody:@"...email body." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
MFMailComposeViewController の単純なカテゴリも機能することがわかりました。アプリを任意の角度に回転させたいので、MFMailComposeViewController+Rotate.h を作成してリンクしました。
#import <Foundation/Foundation.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface MFMailComposeViewController (Rotate)
@end
MFMailComposeViewController+Rotate.m
#import "MFMailComposeViewController+Rotate.h"
@implementation MFMailComposeViewController (Rotate)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
// return the desired orientation mask from http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
return /*mask*/;
}
@end
私のベースライン テスト目的 (iOS 3.1.3) では、ルート ビュー コントローラーに配置する必要はないようです。
これを行う前に、アプリが MFMailComposeViewController を読み込んだ後、MFMailComposeViewController が閉じられた後でも、他の方向への回転が停止することに注意してください。今、私のアプリは自由に回転できます。
- ヘンリー
これは、1つの小さな変更で完全に機能しました。
MailCompose *controller = [[MailCompose alloc]
initWithRootViewController:self.navigationController];
...
initWithRootViewController
そして、基本クラスのメソッドを呼び出さなければならないと確信しました。そうでなければ、MFMailComposeViewController はどのようにそれを知るのでしょうか? しかし、上記の例では、単純に呼び出すだけ[[MailCompose alloc] init]
で十分であることがわかります。基礎となる MFMailComposeViewController は、それ自体を表示する方法を「知っている」だけです。
こういう嬉しいサプライズ大好きです。他の人にとっても同様に明るくなる場合に備えて、これを投稿しました。
新しいコントローラーを作成し、MFMailComposeViewController から継承します。このコントローラーでは、1 つの関数 shouldautorotate を記述するだけです。これのインスタンスを作成します。これで問題なく動作します。