UIScrollView when Autolayout is turned on (StoryBoard)

杀马特。学长 韩版系。学妹 提交于 2019-12-25 06:20:50

问题


I was wrestling with UIScrollview and it knocked me out. I tried to take reference from following two post on stackOverFlow

scrollview xcode4.5 autolayout, Xcode 4.5 UIScrollView, Embed ImageView in ScrollView with Auto Layout on iOS 6,

I tried viewDidLayoutSubviews, as told in UIScrollView setContentSize breaks view with Auto Layout that is causing my app to crash.

And I tried ViewDidLoad, viewDidAppear and viewWillAppear but nothing worked. I tried google and found couple more related post https://coderwall.com/p/zfe8da, http://www.devx.com/wireless/Article/45113

I tried to rethink and didnt find anything fancy that I was not doing. It seems simple, straight approach.

I am out of clues or any guess please help me.

I am using following code, just to mentioned I have 3 images that I have put in the ScrollView. I have stack them on top of each other so there height is more than iPhone screen height. I was expecting it I set them just scroll simple, but guess I was wrong. In Implementation file

_howtoScrollView.frame = CGRectMake(0, 0, 320, 460);
_howtoScrollView.scrollEnabled = YES;
[self.howtoScrollView setContentSize:CGSizeMake(self.howtoScrollView.frame.size.width, 700)];
[self.view addSubview:_howtoScrollView];

In interface file .h

@property (weak, nonatomic) IBOutlet UIScrollView *howtoScrollView;

Anyone who got success with ScrollView while having StoryBoard Autolayout.


回答1:


Try removing _howtoScrollView.frame = CGRectMake(0, 0, 320, 460);, see if it works.

If you really need to change the frame of a view, in Autolayout, you should not set the frame directly in your code, you should modify the Constraint instead.




回答2:


Try to do it without the "addSubview" function. I think that with AutoLayout override your other settings...




回答3:


Using interface builder,

expand your scroll view's Constraints section. Then select 'Horizontal Space Constraint'. Under that section you must be probably having a negative value for the 'constant' value. Change it to 0. It will do the trick.




回答4:


I had this problem too. Apple hid the explanation in the release notes. http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0. Look under the UIKit section.



来源:https://stackoverflow.com/questions/15237921/uiscrollview-when-autolayout-is-turned-on-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!