小编use*_*714的帖子

当方向改变时,UIWebView无法正确调整大小?

我在viewcontroller的视图上添加了一个webview,一个titleLabel和一个coverflowView作为其子视图,我希望它在方向改变时改变大小.我在这个方法中更改了webview的框架:

 - (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration 
Run Code Online (Sandbox Code Playgroud)

如果我以纵向方向启动应用程序,当将iPad从orientationLandscape旋转到orientationPortrait或从orientationPortrait旋转到orientationLandscape时,其内容会调整大小,但是当我以横向方向启动应用程序时,它的内容不会调整大小......但是NSLog显示帧已更改.至于titleLabel和coverflowView,它们可以正确调整大小.我怀疑是不是因为css?我根据webview的高度和宽度使用css控制内容的样式.有人能帮我找到原因吗?代码如下:

- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration {
double i = 0;
NSInteger  width=self.view.frame.size.width;
NSInteger  height=self.view.frame.size.height;
NSLog(@"view :%@",[self.view description]);
switch (toInterfaceOrientation){
    case UIInterfaceOrientationPortrait:
    {    
        NSLog(@"rotate to Portrait");
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
            self.docView.frame=CGRectMake(0, 50, width+20, height-70);
            self.toolbar.frame=CGRectMake(0, 0,height , 50);
            for (UIView * view in [toolbar subviews]) {
                if ([view isKindOfClass:[UIButton class]] && view.tag==kBackButtonTag){
                    view.frame=CGRectMake(width-60, 6, 50, 36);

                }else if([view isKindOfClass:[UIButton class]] && view.tag==kReloadButtonTag){
                    view.frame=CGRectMake(width-160, 6, 80,36 );
                }
            }
            [coverflow setFrame:CGRectMake(0, 0 , width+20, height/2-50)]; …
Run Code Online (Sandbox Code Playgroud)

resize objective-c uiwebview orientation

17
推荐指数
2
解决办法
3万
查看次数

标签 统计

objective-c ×1

orientation ×1

resize ×1

uiwebview ×1