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

查看:22
本文介绍了将 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?

谢谢.

推荐答案

WKInterfaceControllerbecomeCurrentPage() 应该是你要找的.

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天全站免登陆