我的程序甚至没有进入 scrollViewDidScroll
方法。我不知道为什么。我的 View 确实加载看起来像这样:
- (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;
}
}
我也实现了
scrollviewDelegate
在我的界面上是这样的。我不明白我做错了什么。它甚至没有进入名为 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");
}
最佳答案
试用:
self.scrollView.delegate = self;
希望这可以帮助。
关于ios - ScrollView 类 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687029/