2016-07-30 72 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 –