UIScrollView没有向正确的方向滚动 [英] UIScrollView doesn't scroll in the right direction

查看:44
本文介绍了UIScrollView没有向正确的方向滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的错误.我有一个UIViewController,其中的UIScrollView嵌入在UIView中.UIScrollview内的图像很少,但是我需要更多空间,因此我想在当前图像下放置一些图像.我做了所有普通的工作来创建和初始化ScrollView,但是它没有沿UP/DOWN方向滚动,而是向左/向右滚动……这是怎么回事?

I got a weird bug. I have a UIViewController with a UIScrollView embedded inside the UIView. Inside the UIScrollview are few images, but I need more space, so I want to put some images under the current ones. I did all the usual stuff to create and initialize my ScrollView, but instead of scrolling in the UP/DOWN direction, it scrolls LEFT/RIGHT … What is going on?

  • 我在.h中声明了"UIScrollViewDelegate"
  • 我的属性 @属性(弱,非原子)IBOutlet UIScrollView * scrollViewContent; 已连接到IB中的滚动视图

  • I declared "UIScrollViewDelegate" in the .h
  • My property @property (weak, nonatomic) IBOutlet UIScrollView *scrollViewContent; is connected to my scrollview in IB

我的ContentSize声明为: self.scrollViewContent.contentSize = CGSizeMake(self.scrollViewContent.frame.size.width,1000); 以及我是否在ViewDidLoad或viewDidLayoutSubviews中声明它什么都不会改变.

My ContentSize is declared as: self.scrollViewContent.contentSize= CGSizeMake(self.scrollViewContent.frame.size.width, 1000); and whether I declare it in ViewDidLoad or viewDidLayoutSubviews doesn't change anything.

我设置了 self.scrollViewContent.delegate = self; 在ViewDidLoad中

I set self.scrollViewContent.delegate = self; in ViewDidLoad

更新

有趣的是,我尝试设置ContentSize,然后将其打印到控制台.事实证明,高度"(Height)属性始终返回0.此外,请注意,我将宽度"(Width)设置为1500,但打印了2000.我没有使用自动布局.

Interestingly enough, I tried setting the ContentSize and then printing it to the console. As it turns out, the "Height" attribute always returns 0. Also, note that I set the "Width" to 1500, but it prints 2000. I'm not using auto-layout.

 [self.scrollViewContent setContentSize:CGSizeMake(1500, 2000)];

    NSLog(@"contentSize width %f", self.scrollViewContent.contentSize.width);
    NSLog(@"contentSize height %f", self.scrollViewContent.contentSize.height);

结果:

"contentSize宽度2000.000000""contentSize高度0.000000"

"contentSize width 2000.000000" "contentSize height 0.000000"

更新2 如果我在另一个项目中使用完全相同的代码和完全相同的Xib,则可以正常工作……我的实际项目有什么问题?

UPDATE 2 If I take the exact same Code and the exact same Xib in another project, it works just fine… what is wrong with my actual project?

推荐答案

请交叉检查您是否声明

是否使用.h文件的UIScrollViewDelegate.

UIScrollViewDelegate at .h file or not..

在.m文件中

@synthesize scrollViewContent;

@synthesize scrollViewContent;

希望对您有帮助...

Hope it may help you...

这篇关于UIScrollView没有向正确的方向滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆