久久久久久久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)
主站蜘蛛池模板: www.久| 国产在线观看一区二区三区 | 亚洲国产91 | 国产精品视频久久久 | 国产美女黄色片 | 伊人网综合 | 综合久 | 欧美区在线 | 精品91久久久 | 国产精品久久久久久久久污网站 | 欧美日本一区二区 | 涩涩视频在线播放 | 亚洲精品女优 | 精品综合 | 国产精品久久免费观看 | 欧美一区二区三区在线观看 | 亚洲永久精品国产 | 久久久久免费精品国产 | www日韩欧美| www.亚洲精品 | 国产欧美综合在线 | 黑人巨大精品欧美一区二区免费 | 精品视频一区二区 | 涩涩操| 亚洲激情综合 | 一级毛片色一级 | 精品一区二区三区在线视频 | 五月婷婷婷 | 精品一区二区在线观看 | 在线成人www免费观看视频 | 在线观看中文字幕 | 欧美jizzhd精品欧美巨大免费 | 欧美二区在线 | www.亚洲视频| 国产精品一区二 | 中文字幕高清免费日韩视频在线 | 亚洲视频在线观看免费 | 91麻豆久久久 | 久草99| 亚洲欧美一区二区三区国产精品 | 国产精品视频综合 |