UIScrollView doesn't scroll in the right direction

一世执手 提交于 2020-01-06 07:43:27

问题


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?

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

  • 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.

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

UPDATE

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);

Result:

"contentSize width 2000.000000" "contentSize height 0.000000"

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?


回答1:


Please cross check that you declared

UIScrollViewDelegate at .h file or not..

At .m File

@synthesize scrollViewContent;

Hope it may help you...



来源:https://stackoverflow.com/questions/20251844/uiscrollview-doesnt-scroll-in-the-right-direction

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