将Watch App启动到中间视图 [英] Launch Watch App into middle view

查看:148
本文介绍了将Watch App启动到中间视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的应用程序以页面格式布局,我希望它能够启动到三页的中间位置。没有办法设置上一个页面segue,所以我一直在尝试在代码中进行。

Basically, my app is laid out in the page format and I would like it to launch into the middle of the three pages. There is no way of setting a previous page segue, so I have been trying to do it in code.

我将主视图设置为第一个视图,而我一旦应用程序启动,我就尝试了各种方法来调整中间视图。

I have the main view set to the first view, and I have tried a variety of methods to segue to the middle view as soon as the app is launched.

以下是我尝试的两种方法:

Here is the two ways I tried:

    if segueCheck == true {
        self.pushControllerWithName("budget", context: self)
        self.presentControllerWithName("budget", context: self)
        segueCheck = false
    }

第一个出现视图,但作为一个完全独立的视图,第二个视图用中间视图替换第一个视图。

The first presents the view, but as a completely separate view, and the second replaces the first view with the middle view.

有谁知道如何启动到中间视图并允许用户要向左和向右滑动吗?

Does anyone know how I can launch into the middle view and allow the user to swipe left and right of it?

谢谢。

推荐答案

WKInterfaceController becomeCurrentPage() 应该是你想要的。

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

让我们为中心视图控制器创建一个新类, CenterPageViewController ,并更改其 initWithContext:方法,如下所示

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()        
    }
} 

现在让我们为中间设置自定义类故事板中的页面 CenterPageViewController

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

最后点击运行。

你将无法做到摆脱从左侧页面到中间页面的初始转换,但应用程序最终将从中间页面开始。

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.

这篇关于将Watch App启动到中间视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆