久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UIScrollView 框架在 iOS 8 和 iOS 7 上的大小不同

UIScrollView frame is a different size on iOS 8 vs iOS 7(UIScrollView 框架在 iOS 8 和 iOS 7 上的大小不同)
本文介紹了UIScrollView 框架在 iOS 8 和 iOS 7 上的大小不同的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我實現(xiàn)了一個視圖控制器,它只顯示單個圖像并允許用戶通過捏合來放大/平移圖??像.它在 iOS 7 上運行良好,但在 iOS 8 上,滾動視圖的框架大小不同,最終結果是在 iOS 8 上運行時圖像在 iPhone 上放大得太遠而在 iPad 上縮小得太遠.這是因為滾動視圖框架的寬度是 600pt,這是它在情節(jié)提要中的大小(使用大小類的通用情節(jié)提要).但是我有自動布局約束,應該確保滾動視圖伸展以填充可用空間——在 iPad 上應該是 768pt.在 iOS 7 上是這種情況,但在 iOS 8 上不是.

I implemented a view controller that simply displays a single image and allows the user to pinch to zoom in/pan around the image. It works great on iOS 7, but on iOS 8 the scroll view's frame is a different size, and the end result is the image is zoomed in too far on iPhone and zoomed out too far on iPad when running on iOS 8. This is because the scroll view frame's width is 600pt, which is its size in the storyboard (Universal Storyboard using size classes). But I have autolayout constraints that are supposed to ensure the scroll view stretches to fill the available space - it should be 768pt on iPad. That is the case on iOS 7 but not iOS 8.

這是設置:在 Interface Builder 中,我有一個 UIViewController,其中包含一個 UIView,其中包含一個帶有自動布局約束的 UIScrollView,超級視圖的前導、底部和頂部空間.然后在 viewDidLoad:

This is the setup: In Interface Builder, I have a UIViewController that contains a UIView which contains a UIScrollView with autolayout contraints trailing, leading, bottom, and top space to the superview. Then in viewDidLoad:

    UIImage *image = [UIImage imageNamed:@"image"];
    self.imageView = [[UIImageView alloc] initWithImage:image];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);

    [self.scrollView addSubview:self.imageView];
    self.scrollView.contentSize = image.size;

    #warning Bug here - scroll view frame is 600pt on iOS 8 - should be 768 for iPad
    NSLog(@"scroll view frame wid: %f", self.scrollView.frame.size.width);

我發(fā)現(xiàn)如果我將相同的 NSLog 放在 viewDidAppear 中,則框架的寬度是正確的 768pt.我嘗試將該代碼移動到 viewWillAppear 而不是 viewDidLoad,但我得到了相同的結果 - viewWillAppear 中也是 600.因此,滾動視圖正確拉伸以填充顯示,但直到它出現(xiàn)在屏幕上之后.在圖像出現(xiàn)在屏幕上之前,我需要正確的幀大小,以便計算正確的最小和最大縮放值.

I discovered if I put that same NSLog in viewDidAppear the frame's width is correctly 768pt. I tried moving that code into viewWillAppear instead of viewDidLoad, but I get the same outcome - it's 600 in viewWillAppear as well. So the scroll view is properly stretching to fill the display but not until after it appears on screen. I need the correct frame size before the image appears on screen so that I may calculate the proper min and max zoom values.

我能做些什么來解決這個問題并確保它適用于 iOS 7 和 8?

What can I do to fix that and ensure it works for iOS 7 and 8?

推薦答案

我已經解決了.出于某種原因,viewDidLoad 在生命周期中太早了,無法在 iOS 8 上獲取滾動視圖的調整幀,但在 iOS 7 上它再次起作用. viewWillAppear 也太早了,以及 viewWillLayoutSubviews.

I've solved it. For some reason, viewDidLoad is too early in the life cycle to obtain the scroll view's adjusted frame on iOS 8, but again it works on iOS 7. viewWillAppear is also too early, as well as viewWillLayoutSubviews.

為了解決這個問題,我只是將需要使用滾動視圖的幀大小的代碼移到 viewDidLayoutSubviews 中,它最終會獲得正確的大小.

To solve the problem, I just moved the code where I need to use the scroll view's frame size to viewDidLayoutSubviews which does finally obtain the correct size it will be when it appears.

這篇關于UIScrollView 框架在 iOS 8 和 iOS 7 上的大小不同的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 91精品国产91久久久久久最新 | 福利片在线观看 | 亚洲国产精品日韩av不卡在线 | 天天综合网天天综合色 | 国产丝袜一区二区三区免费视频 | www,黄色,com | 久久国产激情视频 | 97人人澡人人爽91综合色 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 | 午夜av免费| 久草网站 | 欧美一区二区精品 | 一区二区三区在线免费观看 | 成人国产精品久久久 | 国产免费一区二区三区 | 日韩视频三区 | 日本午夜网 | 成人免费小视频 | 欧美综合一区二区 | 日韩欧美一区二区三区免费观看 | 午夜精品一区二区三区在线观看 | 亚洲一区二区日韩 | 高清黄色网址 | 播放一级毛片 | 精品国产久 | 欧美成人一级 | 黑人中文字幕一区二区三区 | 欧美日韩国产一区二区 | 一二区成人影院电影网 | 亚洲最大福利网 | 欧美日韩高清一区二区三区 | 国产乱码精品1区2区3区 | 国产在线精品一区二区 | 亚洲成人自拍 | 国产精品久久久久久久久久久久久 | h片在线免费观看 | 精精久久 | 日韩三级在线观看 | 欧美亚州 | 国产综合av | 四虎伊人|