2010-02-24 4 views
6

Soy nuevo en el desarrollo de iphone. En mi aplicación, quiero mostrar la vista web en el dispositivo con c orientación vertical.También debería ser compatible con la orientación horizontal. Usé el siguiente método, pero no hay salida esperada.Webview cambia el tamaño automáticamente a la vista vertical y horizontal en iphone

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

return (interfaceOrientation == UIInterfaceOrientationPortrait || 

interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == 

UIInterfaceOrientationLandscapeRight); 
} 

favor guiar Confíeme me ayude out.Thanks

Respuesta

10

creo que haya configurado el marco fijo para webview.That no ayudará al aplicar la orientación chage

intenta esto:

Usar este código para la visualización de la web-view.Change la pila -overflow URL con su 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]; 

Para apoyar la orientación

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

} 

Para el cambio de vista-web con orientación

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

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

Esperamos que la anterior va a satisfacer sus necesidades. Todo lo mejor.

+0

Gracias. Quiero mostrar la barra de herramientas en mi vista web? ¿Cómo puedo conseguir esto?. No puedo ver la barra de herramientas en mi vista web. – Pugal

+0

@pugal Inserte la barra de pestañas como subvista ... [self.view insertSubview: tBar belowSubview: contentView]; cambie tBar a la barra de herramientas que ha utilizado. – Warrior

0

Si quieres apoyar cualquier orientación a continuación, sólo volver YES.

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

Esto estaba obsoleto en iOS 6: https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#jumpTo_9 – poshaughnessy

Cuestiones relacionadas