使用按钮执行入职页面
Perform Onboarding Pager with a boutton
我正在使用现有项目(https://github.com/ThornTechPublic/Onboarding-With-UIPageViewController-Final ) . I want to perform the slide with a boutton also. I want my button "Next" to do the same functionality as swiping so when the user taps it, it moves to the next screen. Button in blue。如何操作?提前致谢。
我是这样做的:我在页面上使用 NSNotification,它让 OnboardingPager 知道按钮何时被按下,并执行适当的操作。
举个例子:在 StepZero 页面中,我做了以下操作
@IBAction func nextPressed(sender: UIButton) {
NSNotificationCenter.defaultCenter().postNotificationName("testbutton", object: nil)
}
然后在 OnboardingPager class 中,我添加了以下内容
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)。
我正在使用现有项目(https://github.com/ThornTechPublic/Onboarding-With-UIPageViewController-Final ) . I want to perform the slide with a boutton also. I want my button "Next" to do the same functionality as swiping so when the user taps it, it moves to the next screen. Button in blue。如何操作?提前致谢。
我是这样做的:我在页面上使用 NSNotification,它让 OnboardingPager 知道按钮何时被按下,并执行适当的操作。
举个例子:在 StepZero 页面中,我做了以下操作
@IBAction func nextPressed(sender: UIButton) {
NSNotificationCenter.defaultCenter().postNotificationName("testbutton", object: nil)
}
然后在 OnboardingPager class 中,我添加了以下内容
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)。