UIScrollView不向正确的方向滚动
我有一个奇怪的错误。 我有一个UIViewController UIScrollViewembedded在UIView内。 在UIScrollview里面的图片很less,但是我需要更多的空间,所以我想把一些图片放在当前的图片下。 我做了所有常用的东西来创build和初始化我的ScrollView,但不是在向上/向下滚动,它滚动左/右…发生了什么事情?
- 我在.h中声明了“UIScrollViewDelegate”
-
我的属性
@property (weak, nonatomic) IBOutlet UIScrollView *scrollViewContent;
连接到我在IB的滚动视图 -
我的ContentSize声明为:
self.scrollViewContent.contentSize= CGSizeMake(self.scrollViewContent.frame.size.width, 1000);
以及我是否在ViewDidLoad或viewDidLayoutSubviews中声明它不会改变任何东西。 -
我设置
self.scrollViewContent.delegate = self;
在ViewDidLoad中
UPDATE
有趣的是,我尝试设置ContentSize,然后将其打印到控制台。 事实certificate,“高度”属性总是返回0.此外,请注意,我将“宽度”设置为1500,但它打印2000.我没有使用自动布局。
[self.scrollViewContent setContentSize:CGSizeMake(1500, 2000)]; NSLog(@"contentSize width %f", self.scrollViewContent.contentSize.width); NSLog(@"contentSize height %f", self.scrollViewContent.contentSize.height);
结果:
“contentSize width 2000.000000”“contentSize height 0.000000”
更新2如果我在另一个项目中采用完全相同的代码和完全相同的Xib,它的工作正常…我的实际项目有什么问题?
请核对你的声明
UIScrollViewDelegate在.h文件或不..
在.m文件
@synthesize scrollViewContent;
希望它可以帮助你…