我正在尝试将 UIPageControl 与我的 UIScrollView 一起使用。似乎我做错了什么,因为页面总是设置为一个。
这是我的 ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView.delegate = self;
UIImageView *imgView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen1.png"]];
imgView1.frame = CGRectMake(0, 0, 320, 436);
[scrollView addSubview:imgView1];
UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen2.png"]];
imgView2.frame = CGRectMake(320, 0, 320, 436);
[scrollView addSubview:imgView2];
UIImageView *imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutorialScreen3.png"]];
imgView3.frame = CGRectMake(640, 0, 320, 436);
[scrollView addSubview:imgView3];
scrollView.contentSize = CGSizeMake(960, 436);
pageControl = [[UIPageControl alloc] init];
[pageControl setNumberOfPages:3];
[pageControl setCurrentPage:0];
}
这是我的 UIScrollView 委托方法:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollViewx{
NSLog(@"%f",scrollView.contentOffset.x);
NSLog(@"%f",(scrollViewx.contentOffset.x / 320));
pageControl.currentPage = ((scrollViewx.contentOffset.x / 320));
}
这是 y .h 文件:
@interface TutorialViewController : UIViewController <UIScrollViewDelegate>
@property (nonatomic,strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic,strong) IBOutlet UIPageControl *pageControl;
@end
有谁知道为什么它不改变?当然,我确保我的 UIPageControl 已连接到它的实例。
感谢你的帮助...