UIScrollView 似乎不适用于 xcode 6 (iOS 8)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25105594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIScrollView doesn’t seem to work in xcode 6 (iOS 8)
提问by Mats
I'm trying to make a scroll view in xcode. I used the following code in xcode 5 (which worked):
我正在尝试在 xcode 中制作滚动视图。我在 xcode 5(有效)中使用了以下代码:
view.h:
视图.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIScrollView *ScrollView;
}
@end
view.m
视图.m
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[ScrollView setScrollEnabled:YES];
[ScrollView setContentSize:CGSizeMake(320, 1005)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
I have seen others with this problem but none of their solutions worked for me. Note that i have size set to freedom and auto layout is turned off.
我见过其他人有这个问题,但他们的解决方案都不适合我。请注意,我已将大小设置为自由并且关闭了自动布局。
回答by grgmo
Try this - UIScrollView with Autolayout
试试这个 -带有自动布局的 UIScrollView
OR
或者
try setting your content size in viewDidAppear
尝试在 viewDidAppear 中设置您的内容大小
回答by trumpeter201
Due to a scrollView feature in auto layout, the contentSize is being redefined. To solve this problem, you could disable auto layout or set the content size in viewDidLayoutSubviews()
由于自动布局中的 scrollView 功能,正在重新定义 contentSize。要解决此问题,您可以禁用自动布局或在 viewDidLayoutSubviews() 中设置内容大小
-(void)viewWillLayoutSubviews {
[super viewDidLayoutSubviews];
ScrollView.contentSize = CGSizeMake(320,1005);
}
So you would want to add this code and delete the ScrollView.contentSize method in viewDidLoad.
因此,您可能希望添加此代码并删除 viewDidLoad 中的 ScrollView.contentSize 方法。
回答by JustAnotherCoder
I don't see anything immediately wrong with this code. I would check and makes sure that you've connected the IBOutlet properly in the Interface Builder.
我看不出这段代码有什么问题。我会检查并确保您已在 Interface Builder 中正确连接了 IBOutlet。