0
我試圖用一個UIPageControl與我的UIScrollView。看來我做了不正當的事情,導致頁面始終設置爲1。的PageControl頁面處理
這是我的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連接到它的實例。
感謝您的幫助......
什麼是scrollViewDidEndDecelerating日誌顯示?如果你添加一個NSLog(「UIPageControl頁面:%d」,pageControl.currentPage);在scrollViewDidEndDecelerating的末尾顯示了什麼? – Obliquely
320,1.0000和1 –
而當您嘗試滾動以使320變爲零或640時,那麼呢? - 額外的問題:你似乎正在重新分配和初始化你的頁面控制。如果你已經用IB連接了它,那麼這樣做會創建一個新實例並打斷你的連接。 – Obliquely