如何在没有手势的情况下自动触发翻页过渡?

时间:2014-07-18 16:15:48

标签: ios xcode uipageviewcontroller

我正在使用带有PageControl的UIPageViewController在我的PageViewController中显示图像。一切都很完美。但页面是否有可能在特定时间后自动滑动(滚动)到下一页?

Y有这个代码,但不工作,我需要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];


}

2 个答案:

答案 0 :(得分:2)

你输了一个拼写错误:

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

您提供了选择器名称animacion,但您的方法称为animation

答案 1 :(得分:1)

定时器不能在主循环中运行。试试这个:

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