2014-07-18 21 views
0

我正在使用帶有PageControl的UIPageViewController在我的PageViewController中顯示圖像。所有作品都很完美但頁面是否可能自動在特定時間後滑動(滾動)到下一頁?你有這個代碼,但不工作,我需要UIPageViewController自動滾動。如何在沒有手勢的情況下自動觸發翻頁過渡?

NSTimer *aTimer; 
NSArray *viewControllers; 


-(void)viewDidAppear:(BOOL)animated{ 

    aTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(animacion) userInfo:nil repeats:YES]; 

} 


-(void)animation{ 

[pageVCObj setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; 
} 



- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 


    self.pageController.doubleSided =YES; 

    self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; 

    self.pageController.dataSource = self; 
    [[self.pageController view] setFrame:[[self view] bounds]]; 

    APPChildViewController5 *initialViewController = [self viewControllerAtIndex:0]; 

    viewControllers = [NSArray arrayWithObject:initialViewController]; 

    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 

    [self addChildViewController:self.pageController]; 
    [[self view] addSubview:[self.pageController view]]; 
    [self.pageController didMoveToParentViewController:self]; 


} 

回答

1

定時器不得在主循環中運行。試試這個:

aTimer = [[NSRunLoop mainLoop] addTimer:[NSTimer timerWithTimeInterval:2 target:self selector:@selector(animacion) userInfo:nil repeats:YES]]; 
2

你有一個錯字:

aTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(animacion) userInfo:nil repeats:YES]; 

您提供選擇的名稱animacion但你的方法被調用animation

+0

hehehe ops .....這不會再發生 – Fabio

相關問題