简体   繁体   中英

Why is my UIImageView's frame greater than the screen size?

I have a single view application (see below layout ). The layout was done using iphone x. I have a central UIImageView that is within the safe area along with a custom bottom UIView that has some UIButtons. When I run the application on a iphone 6 plus (which does not have a notch) and run the code below, I get back a frame for the UIImage view that is larger than the screen dimensions AND the frame has a top inset of 44. I do not understand how this is possible?

override func viewDidLoad() {
    super.viewDidLoad()

    print("self.imgPreViewOutlet.frame: \(self.imgPreViewOutlet.frame)")
    print("self.imgPreViewOutlet.bounds: \(self.imgPreViewOutlet.bounds)")
    print("UIScreen.main.bounds: \(UIScreen.main.bounds)")

}

Console:

self.imgPreViewOutlet.frame: (0.0, 44.0, 414.0, 758.0)
self.imgPreViewOutlet.bounds: (0.0, 0.0, 414.0, 758.0)
UIScreen.main.bounds: (0.0, 0.0, 414.0, 736.0)

Layout has not yet happened in viewDidLoad . The size you get there is meaningless. Ignore it. If you want to know how big the image view will really be, wait until later in the birth cycle of you view controller, such as viewDidLayoutSubviews .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM