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

如何使用 Autolayout 在我的 UIScrollview 上設(shè)置約束

How can I use Autolayout to set constraints on my UIScrollview?(如何使用 Autolayout 在我的 UIScrollview 上設(shè)置約束?)
本文介紹了如何使用 Autolayout 在我的 UIScrollview 上設(shè)置約束?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我花了兩天時(shí)間嘗試了 ,而不是解釋您的設(shè)置有什么問(wèn)題具有與您描述的非常相似的視圖層次結(jié)構(gòu)和約束設(shè)置.水平滾動(dòng)在示例項(xiàng)目中按預(yù)期工作,它使用 Apple 在 技術(shù)說(shuō)明.

最初讓自動(dòng)布局與 UIScrollView 一起工作時(shí),我也遇到了很多麻煩.讓它工作的關(guān)鍵是確保滾動(dòng)視圖中的所有項(xiàng)目加在一起,具有最終鏈接到滾動(dòng)視圖所有方面的約束,并有助于自動(dòng)布局系統(tǒng)能夠確定 contentSize 為滾動(dòng)視圖將大于其框架.看起來(lái)您正在嘗試在代碼中執(zhí)行此操作,但可能您有一些多余的約束導(dǎo)致 contentSize 太小.

另外值得注意的是,正如其他人提到的,使用 AutoLayout 和 UIScrollview,您不再顯式設(shè)置 contentSize.AutoLayout System 根據(jù)您的約束計(jì)算 contentSize.

我還發(fā)現(xiàn) 此電子書(shū)章節(jié) 非常有助于讓我了解所有這行得通.希望這對(duì)您有所幫助.

I have spent two days trying out the various solutions for Mixed and Pure Autolayout approaches to achieve what was a trivial scrollview setup prior to autolayout, and it's now official - I must be too stupid. I am setting this up mostly in Storyboard (well, it's just the way it is).

So here's my plea for help.

Viewtree:

UIView
-UIView
-UIView
..-UIScrollview
...-UIButton
...-UIButton
...-UIButton

The buttons are supposed to scroll horizontally (left to right and vice versa). Can someone please let me know how to set the constraints to achieve this using pure Autolayout???

--

I have tried the mixed approach, like so:

UIView
- UIView
- UIView
..-UIScrollview
...-UIView (contentview)
....-UIButton
....-UIButton
....-UIButton

...and setting fixed width and height constraints for the contentview and the translatesAutoresizingMaskIntoConstraints settings as per Apple's TechNote. The buttons and scrollview are set up using constraints. This gets the scrollview scrolling (yay) but alas, it scrolls too far! As far as I can tell, the scroll width is somehow doubled from what I set the contentview at???!!!???

I tried the pure autolayout approach as well, both with contentview and without. All the views are translatesAutoresizingMaskIntoConstraints=NO, except for self.view. The buttons have fixed width/height constraints, and are pinned to all four edges of the scrollview. Nothing scrolls.

So I am totally baffled why I can't get it to work correctly. Any help is much appreciated, and if you need any other info, please ask!

UPDATED Screenshot with solution - buttonZ constraints:

EDIT @ Jamie Forrest So the solution turns out to be the wrong trailing constraint on the last button. Instead of 6441, the value I had set was negative, -6441. The tricky thing is, that when setting the value in storyboard, there are two options in the Pin toolbar:

The Current Canvas Value is negative (leading to no scroll), and the option below is positive (activating scroll). This means I'm not stupid but at least half-blind I guess. Although, to my defense, isn't it somewhat disturbing that XCode doesn't show an error for the "incorrect" setting?

EDITED AGAIN Now this is funny... changing the trailing value from -6441 (no scroll) to 6441 enabled scroll. But my old friend the "too much contentsize" was back, leading to a content size twice as large as what it should be! The solution to get the correct content scroll was to set the trailing constraint to ZERO! This is not obvious when working in Storyboard but looking at @Infinity James' code, it is what it should be.

解決方案

It's hard to see the exact values and setup of your constraints as you've pasted them here, so I'm not sure from looking at your screenshots where you have gone wrong.

In lieu of an explanation of what's wrong in your setup, I've created a basic sample project with a very similar view hierarchy and constraint setup to the one you describe. The horizontal scrolling works as expected in the sample project, which uses the "Pure AutoLayout" approach that Apple describes in the Technical Note.

I also had a lot of trouble originally getting Auto Layout to work with UIScrollView. The key to getting it to work is making sure that all of the items in the scroll view, taken together, have constraints that eventually link to all sides of the scroll view and that contribute to the AutoLayout system being able to determine a contentSize for the scroll view that will be bigger than its frame. It looks like you were trying to do that in your code, but maybe you had some superfluous constraints in there that were making the contentSize too small.

Also of note, as others mentioned, with AutoLayout and UIScrollview, you no longer set the contentSize explicitly. The AutoLayout System calculates the contentSize based on your constraints.

I also found this ebook chapter to be very helpful in making me understand how all this works. Hope all this helps.

這篇關(guān)于如何使用 Autolayout 在我的 UIScrollview 上設(shè)置約束?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫(kù)中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁(yè)面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 蜜臀久久99精品久久久久宅男 | 久久久夜色精品亚洲 | 亚洲精品一二三 | 日本黄a三级三级三级 | 一级片免费 | 久久精品视频国产 | www一级片| 丰满少妇av | 日本不卡高字幕在线2019 | 色综合久久天天综合网 | 欧美一区二区精品 | 日韩成人影视 | 一区二区三区网站 | 亚洲激情视频在线观看 | 成人精品免费视频 | 国产黄色在线 | 午夜在线观看视频网站 | 激情av小说 | 日韩网站免费观看 | 九九影视理伦片 | 国产一区在线播放 | 日韩综合一区 | 93久久精品日日躁夜夜躁欧美 | 欧美xxxx网站 | 在线观看91视频 | 国产一区二区三区在线看 | 国产伦精品一区二区三毛 | 日韩网站在线观看 | 欧美日本一区 | 天天干夜夜操 | 日韩激情视频 | 最新国产精品视频 | 青青草久久 | 一区二区三区国产 | 欧美一区二区三 | 奇米影视亚洲春色 | 成人免费视频一区二区 | 午夜在线影院 | 婷婷综合网 | www.亚洲天堂| 国产一区久久 |