UIPageControl不响应触摸,不改变点

Ale*_*x L 6 iphone cocoa-touch objective-c uikit ios4

我有一个UIPageControl.当我点击一个点来更改页面时,没有任何反应.第二个点不会突出显示.

但是,当我滚动我的UIScrollView时它工作正常.在这种情况下,第二个点突出显示.

pageControl = [[UIPageControl alloc] init] ;
pageControl.center = CGPointMake(160.0f, 430.0f);
pageControl.numberOfPages=nPages;
pageControl.currentPage=0;
pageControl.hidesForSinglePage = YES;
pageControl.userInteractionEnabled =YES;

[pageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:pageControl];
Run Code Online (Sandbox Code Playgroud)

这应该在我更改pageControl Value时调用,但由于它不响应触摸而不会被调用.

- (void) pageTurn: (UIPageControl *) aPageControl
{
    int whichPage = aPageControl.currentPage;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    sv.contentOffset = CGPointMake(320.0f * whichPage, 0.0f);
    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

小智 17

设置pagecontrol的框架(宽度和高度),而不仅仅是中心,否则它具有零维度并且不响应触摸.

pageControl = [[UIPageControl alloc] 
                 initWithFrame:CGRectMake(100, 430, 200, 50)];
pageControl.center = CGPointMake(160.0f, 430.0f);
Run Code Online (Sandbox Code Playgroud)