私はiPhoneの開発に不慣れです。私のアプリでは、多数のviewController、Webビュー、ツールバー、タブバーなどを使用しています。ここでは、すべてのWebビューで、対応するデバイスビューの向き(縦向きまたは横向き、あるいはその逆)を実現したいと考えています。これらのWebビューがタブバーコントローラーWebビューの下にあることを除いてすべてのWebビューで方向付けを行うことができました(タブバービューコントローラーまたはタブバーコントローラービューのサブビューのいずれかである可能性があります)。
ここでは、以下のコードを使用してWebビューを追加します。
contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view = contentView;
self.view.autoresizesSubviews = YES;
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y -= 20.0;
webView1 = [[UIWebView alloc] initWithFrame:webFrame];
[contentView addSubview:webView1];
オリエンテーションを達成するために以下の方法を使用して、
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation
{
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
[webView1 stringByEvaluatingJavaScriptFromString:@"rotate(0)"];
}
そうしないと {
[webView1 stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
}
}
誰でも解決してください!