2010-02-24 3 views
6

Je suis nouveau dans le développement de l'iphone. Dans mon application, je veux afficher la vue web dans l'appareil avec c portrait Orientation.Il devrait également soutenir l'orientation paysage. J'ai utilisé la méthode ci-dessous, mais il n'y a pas de sortie attendue.Webview redimensionne automatiquement en mode portrait et paysage dans l'iphone

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

return (interfaceOrientation == UIInterfaceOrientationPortrait || 

interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == 

UIInterfaceOrientationLandscapeRight); 
} 

s'il vous plaît aidez-moi guider me.Please out.Thanks

Répondre

10

Je pense que vous avez défini le cadre fixé pour webview.That ne sera pas utile en mettant en œuvre l'orientation chage

Essayez ceci:

Utilisez ce code pour afficher le web-view.Change la pile l'URL de -overflow avec votre URL;

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; 

webView = [[UIWebView alloc] initWithFrame:webFrame]; 

[contentView addSubview:webView]; 
webView.scalesPageToFit = YES; 
webView.autoresizesSubviews = YES; 
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth); 
[webView setBackgroundColor:[UIColor clearColor]]; 
NSString *urlAddress = @"https://www.stackoverflow.com"; 
NSURL *url = [NSURL URLWithString:urlAddress]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:requestObj]; 
webView.delegate =self; 
[webView release]; 

Pour soutenir l'orientation

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{ 
return YES; 

} 

Pour le changement Web avec vue orientation

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){ 
[webView stringByEvaluatingJavaScriptFromString:@"rotate(0)"]; 

} 
else{ 
    [webView stringByEvaluatingJavaScriptFromString:@"rotate(1)"]; 
} 
} 

Espérons que ce qui précède satisfaire vos besoins. Tout le meilleur.

+0

Merci. Je veux afficher la barre d'outils dans mon webview? Comment puis-je atteindre cet objectif?. Je ne suis pas en mesure de voir la barre d'outils dans mon webview. – Pugal

+0

@pugal Insérer la barre d'onglets comme sous-vue ... [self.view insertSubview: tBar belowSubview: contentView]; Modifiez tBar sur la barre d'outils que vous avez utilisée. – Warrior

0

Si vous voulez soutenir toute orientation puis juste revenir YES.

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{ 
    return YES; 
} 
+0

Ceci était obsolète dans iOS 6: https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#jumpTo_9 – poshaughnessy

Questions connexes