0

UIScrollViewでUIPageControlを使用しようとしています。ページが常に1に設定されているため、不適切な処理を行っているようです。

これは私の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がそのインスタンスに接続されていることを確認しました。

あなたの助けに感謝...

4

1 に答える 1

0

わかった。IBで設定したものを使用する代わりに、新しいUIPageControlを作成したため、ドットは変更されません。テイクアウト:pageControl = [[UIPageControl alloc] init];

于 2012-12-09T18:34:28.620 に答える