我是iOS新手,只需创建一个小型本机应用程序,该应用程序加载一个URL,该URL托管在IIS上并在Jquery移动设备上制作。 问题是当我改变方向时它是从右侧剪切,而同样的东西在所有Android设备上正常工作。 请帮帮我
这是我的代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *webView=[[UIWebView alloc]initWithFrame:CGRectMake(0.0, 0.0,768,1024)];
NSString *httpSource=@"http://www.mydomain.com";
NSURL *fullUrl=[NSURL URLWithString:httpSource];
NSURLRequest *httpRequest=[NSURLRequest requestWithURL:fullUrl];
webView.delegate=self;
[webView loadRequest:httpRequest];
[self.view addSubview:webView];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:6)
您必须为webView设置自动调整大小,或者您可以使用Autolayout。
- (void)viewDidLoad {
[super viewDidLoad];
//Here you use the frame of Total View, irrespective of device type
UIWebView *webView=[[UIWebView alloc]initWithFrame:self.view.bounds];
//Autoresizemask
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
NSString *httpSource=@"http://www.mydomain.com";
NSURL *fullUrl=[NSURL URLWithString:httpSource];
NSURLRequest *httpRequest=[NSURLRequest requestWithURL:fullUrl];
webView.delegate=self;
[webView loadRequest:httpRequest];
[self.view addSubview:webView];
}
答案 1 :(得分:0)
尝试在设备旋转时更改UIWebView
帧。试试下面的代码
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[webView setFrame: CGRectMake(0, 0, 1024, 768)];
}