Launch Watch App into middle view

大憨熊 提交于 2019-12-05 03:30:32

WKInterfaceController's becomeCurrentPage() should be what you're looking for.

Let's create a new class for the center view controller, CenterPageViewController, and change its initWithContext: method as follows

import WatchKit

class CenterPageViewController: WKInterfaceController {

    override init(context: AnyObject?) {
        super.init(context: context)

        super.becomeCurrentPage()        
    }
} 

Now let's set the Custom Class for the middle page in your storyboard to CenterPageViewController

and finally hit run.

You won't be able to get rid of the initial transition from the left page to the center page, but the app will finally begin on the middle page.

Update Swift 3.0

class CenterPageViewController: WKInterfaceController {

override init (){
    super.init()
    super.becomeCurrentPage()
  }
}

This will works...!!!

Thanks

The new way to do this in watchOS 4 and higher is:

WKInterfaceController.reloadRootPageControllers(withNames: 
["Controller1" "Controller2", "Controller3"], 
 contexts: [context1, context2, context3],
 orientation: WKPageOrientation.horizontal,
 pageIndex: 1)

Now you don't get the annoying animation when using becomeCurrentPage() when you want to start with the middle page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!