2016-07-30 74 views
2

我正在使用现有项目(https://github.com/ThornTechPublic/Onboarding-With-UIPageViewController-Final)。我也想用boutton来演奏幻灯片。我希望我的按钮“下一步”执行与滑动相同的功能,因此当用户点击它时,它会移动到下一个屏幕。 Button in blue。怎么做 ?提前致谢 。使用boutton执行启动寻呼机

+0

我投票将此问题标记为重复:http://stackoverflow.com/questions/7208871/is-it-possible-to-turn-page-programmatically-in-uipageviewcontroller –

+0

不一样的问题队友; ) –

回答

1

下面是我该如何做的:在页面上使用NSNotification,让OnboardingPager知道何时按下按钮,并执行相应的操作。

下面是一个例子:在StepZero页,我做了以下

@IBAction func nextPressed(sender: UIButton) { 
    NSNotificationCenter.defaultCenter().postNotificationName("testbutton", object: nil) 
} 

然后在OnboardingPager类,添加以下

override func viewDidLoad() { 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(nextPage(_:)), name: "testbutton", object: nil) 
} 

func nextPage(notification:NSNotification) { 
    self.setViewControllers([getStepOne()], 
      direction: UIPageViewControllerNavigationDirection.Forward, 
      animated: true, 
      completion: nil) 
} 

这可以让你从第一页去( StepZero)到第二个(StepOne)。

+0

谢谢你man:D –