Swift 如何在故事板中设计 UIWebView 自动调整全屏大小 [英] Swift how to design UIWebView Auto resize full screen in Story Board

查看:36
本文介绍了Swift 如何在故事板中设计 UIWebView 自动调整全屏大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 StoryBoard 中设计了一个 320x500 的 UIWebView.但是当在 Iphone 6 Plus Simulator 中运行时,我想要这个 webview 全屏或随着设备的屏幕缩放.如何在故事板中制作它?

I designed a UIWebView with 320x500 in StoryBoard. But when run in Iphone 6 Plus Simulator, i want to this webview full screen or scale with the screen of device. How to make it in storyboard?

我在 ViewDidLoad 中编写了代码但不起作用.

I wrote code in ViewDidLoad but not working.

override func viewDidLoad() {
        super.viewDidLoad()
        self.detailWebView.frame = self.view.frame;
        println("H:\(self.view.frame.height), W:\(self.view.frame.width)")
        self.configureView()
    }

self.view.frame 的高度和宽度好像是真的,但是这个 webview 的大小还是 320X500

Seem to be self.view.frame height and width that true, but size of this webview stills 320X500

推荐答案

在 ViewDidLoad 和使用自动布局时,尚未计算框架.因此,将您的代码放在 viewDidLayoutSubviews 或 viewDidAppear 中,这应该可以修复错误.

In ViewDidLoad and when you use autolayout, the frame is not yet calculated. So, place your code in viewDidLayoutSubviews or in viewDidAppear, and that should fix the bug.

你也可以解决这个问题,只需在你的界面构建器中添加约束(不要忘记在 viewDidLoad 中删除你的代码):

You can also fix that, only by adding constraints in your interface builder (do not forget to remove your code in viewDidLoad) :

这篇关于Swift 如何在故事板中设计 UIWebView 自动调整全屏大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆