OGeek|极客世界-中国程序员成长平台

标题: ios - 从其他应用返回应用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:11
标题: ios - 从其他应用返回应用

您好,

当我们与我们 iphone 通话并且您离开通话 View 返回跳板时,我们可以通过状态栏返回通话 View 。 (这张图更能说明:http://what-when-how.com/wp-content/uploads/2011/08/tmpB178_thumb.jpg)

或者,在 Facebook 应用程序中,当您转到Messenger Facebook 应用程序(不是同一个应用程序)时,我们也可以触摸状态栏来返回 Facebook 应用程序。

我想知道是否可以在我的应用程序中制作它?如果可能的话,我将如何进行? (编辑:我想从另一个应用程序(例如 Youtube)回到我的应用程序。)

谢谢



Best Answer-推荐答案


一旦您熟悉了如何在当前应用表单中打开另一个应用,请点击以下链接:

http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

您可以简单地创建一个具有点击手势的 View 并将其用作按钮

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.navigationController setNavigationBarHidden:YES];

    UIView *tapToReturnButton = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
    tapToReturnButton.backgroundColor = [UIColor blueColor];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                      actionselector(tapToReturnButtonClicked)];
    [tap setNumberOfTouchesRequired:1];
    [tapToReturnButton addGestureRecognizer:tap];

    UILabel *tapToReturnLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 20)];
    tapToReturnLabel.text = @"Tap to return";
    tapToReturnLabel.textColor = [UIColor whiteColor];
    tapToReturnLabel.textAlignment = NSTextAlignmentCenter;
    tapToReturnLabel.font = [UIFont fontWithName"ArialMT"
                                        size:14];

    [tapToReturnButton addSubview:tapToReturnLabel];
    [self.view addSubview:tapToReturnButton];
}


- (void)tapToReturnButtonClicked
{
    NSLog(@"Now you add your code that opens another app(URL) here");
}

已编辑:

在我发布上面的代码后,我有点意识到即使 tapToReturnButton 的其他底部(20 像素)有点击手势,状态栏上也不会出现点击手势。在我做了一些研究之后,我认为以下链接对点击手势有更好的解决方案。我可能会使用 tapToReturnButton 作为占位符,让用户知道触摸的位置并删除 UITapGestureRecognizer *tap。

How to detect touches in status bar

同样,我认为有多种方法可以满足您的需求,但上面的链接将为您提供良好的起点。

关于ios - 从其他应用返回应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23458248/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4