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

UIScrollView 使用自動布局縮放

UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
本文介紹了UIScrollView 使用自動布局縮放的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試實現 UIScrollView 新方式,使用自動布局.我已經設置了從內部視圖到滾動視圖的約束,以便它可以自動計算自己的 contentSize,這就像一個魅力——除了當我嘗試放大時所有的地獄都崩潰了或出去.我什至無法恰當地描述發生了什么,只能說內心的看法搞砸了".

I'm trying to implement a UIScrollView the New Way, using Auto Layout. I've set up constraints from the inner view to the scroll view so that it can compute its own contentSize automatically, and that works like a charm— except that all hell breaks loose when I try to zoom in or out. I can't even properly describe what happens, other than to say that the inner view gets "messed up".

您可以在此處查看此行為的示例(不是我的項目; 您必須設置滾動視圖的 maximumZoomScale 并實現 -viewForZoomingInScrollView: 才能進行縮放).

You can see an example of this behavior here (not my project; you have to set the scroll view's maximumZoomScale and implement -viewForZoomingInScrollView: before zooming will work).

還有其他人遇到過這種行為嗎?目前有什么方法可以放大 UIScrollView 以使用自動布局,而無需自己重新實現縮放行為?

Has anyone else run into this behavior? Is there currently any way to get zooming in a UIScrollView to work with Auto Layout without essentially re-implementing the zooming behavior yourself?

推薦答案

我見過的最好的答案是 Mark 的 (https://stackoverflow.com/users/1051919/mark-kryzhanouski),發布在這里:UIScrollView 縮放不適用于自動布局.

The best answer that I have seen is Mark's (https://stackoverflow.com/users/1051919/mark-kryzhanouski), posted here: UIScrollView Zoom Does Not Work With Autolayout.

關鍵是你必須將嵌套在滾動視圖中的圖像視圖錨定到滾動視圖的父級.盡管 iOS 6 發行說明中提供了指導,但對我來說,哪個視圖浮動"于什么之上并不直觀.在這種情況下,滾動視圖只是一個圖像視圖.

The crux of it is that you have to anchor the image view that is nested in the scroll view, to the parent of the scroll view. Despite the guidance in the iOS 6 release notes, it is not intuitive to me what view is "floating" over what. In this case, the scrolling view is just a single image view.

我確實對此做了很多實驗,希望找到一種全 IB 的方法,但沒有找到.您仍然可以在 IB 中生成視圖層次結構,但您仍然必須以編程方式添加約束.您可以刪除部分或全部默認約束(主要只是為了安撫約束沖突警告),但您始終需要 Mark 的代碼將圖像視圖綁定到滾動視圖的父級,即圖像視圖的祖父級.

I did do a lot of experimentation with this, hoping to find an all-IB approach and found none. You can still generate the view hierarchy in IB, but you still have to programatically add constraints. You can delete some or all of the default constraints (mainly just to appease the constraint-conflict warnings), but you always need Mark's code to tie the image view to the parent of the scroll view, the grand-parent of the image view.

似乎它應該比這更簡單 - 它應該可以工作"但是:

It seems like it should be simpler than this - it "should just work" but:

NSDictionary *viewsDictionary = @{ @"scrollView": self.scrollView, @"imageView": self.imageView };
[self.view addConstraints:[NSLayoutConstraint
    constraintsWithVisualFormat:@"H:|[imageView(width)]"
    options:0
    metrics:@{@"width": @(self.imageView.image.size.width)}
    views:viewsDictionary]];

[self.view addConstraints:[NSLayoutConstraint
    constraintsWithVisualFormat:@"V:|[imageView(height)]"
    options:0
    metrics:@{@"height": @(self.imageView.image.size.height)}
    views:viewsDictionary]];

這篇關于UIScrollView 使用自動布局縮放的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
iOS/Swift - Hide/Show UITabBarController when scrolling down/up(iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarController)
主站蜘蛛池模板: 国产成人精品一区二区 | 国产日韩欧美一区二区 | 96久久久久久 | 在线不卡一区 | 亚洲精品久久久久中文字幕欢迎你 | 久久午夜国产精品www忘忧草 | 久久精品国产免费看久久精品 | 亚洲一区二区三区视频 | 一区二区三区不卡视频 | 国产日韩一区二区三免费 | 亚洲成人免费 | 秋霞电影一区二区三区 | 亚洲区一区二区 | 中文字幕亚洲欧美日韩在线不卡 | 久草中文网 | 蜜臀久久99精品久久久久久宅男 | 毛片a | 极情综合网 | 欧美一级在线视频 | 国产精品视频一区二区三区, | 国产成人精品在线播放 | 色婷婷综合久久久中字幕精品久久 | 久久噜噜噜精品国产亚洲综合 | 午夜合集| 综合精品 | 亚洲巨乳自拍在线视频 | 91精品国产一区 | 欧美一区两区 | 午夜精品久久久久久久99黑人 | 欧美日韩一区二区三区在线观看 | 国产免费视频 | 四虎海外 | 中文字幕不卡在线88 | 国产欧美精品区一区二区三区 | 成人激情免费视频 | 日韩男人天堂 | 中文在线一区二区 | 精品久久影院 | 在线播放国产一区二区三区 | 国产99久久精品 | 亚洲欧洲视频 |