Scroll VIiew Class iOS

十年热恋 提交于 2019-12-11 07:56:22

问题


My program doesnt even go into the scrollViewDidScroll method. I have no idea why. My view did load looks like this:

- (void)viewDidLoad
{
   [super viewDidLoad];

   // Set the size of the content to be displayed
   self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.size.width * ScrollViewControllerNumberOfPages, self.scrollView.bounds.size.height);

   // Turn on paging in the scroll view (can also be done in Interface Builder)
   self.scrollView.pagingEnabled = YES;

   NSLog(@"CurrentPage ViewDidLoad%@",self.pageControl.currentPage);
   switch (self.pageControl.currentPage)
   {
       case 1:
           [self.minkyImageView setImage:[UIImage imageNamed:@"monkey_1.png"]]; 
           NSLog(@"case1");
           break;
       case 2:
           [self.minkyImageView setImage:[UIImage imageNamed:@"Shape1.png"]];
            NSLog(@"case2");
           break;
       default:
           break;
   }     
}

Also i have implemented the scrollviewDelegate on my interface like this. I don't see what i am doing wrong. It doesn't even go into the method called scrollViewDidScroll.

@interface MinkyScreenSwapViewController: UIViewController <UIScrollViewDelegate>

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat contentWidth = scrollView.bounds.size.width;
CGFloat halfContentWidth = contentWidth / 2;
NSInteger currentPage = (scrollView.contentOffset.x + halfContentWidth) / contentWidth;
self.pageControl.currentPage = currentPage;
NSLog(@"CurrentPage");
}

回答1:


Try out:

self.scrollView.delegate = self;

Hope this helps.




回答2:


Try these codes

scrollView.delegate = self;

scrollView.userInteractionEnabled=YES;

If you are adding scroll view over image view, you have to explicitly set

imageView.userInteractionEnabled=YES;

For more convenience set

[[scrollView superView] setUserInteractionEnabled:YES];

These will make your scrollView delegate method active.



来源:https://stackoverflow.com/questions/9687029/scroll-viiew-class-ios

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