关闭Popover并点按一下即可打开新的 [英] Close Popover and open new one with one tap

查看:152
本文介绍了关闭Popover并点按一下即可打开新的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple的移动人机接口指南说关于弹出窗口:

Apple's "Mobile Human Interface Guidelines" says about Popovers:


如果可能,允许人们关闭一个弹出窗口并打开一个新的
,只需点击一下。
当几个
不同的栏按钮各自打开一个弹出窗口时,这种行为尤其可取,因为它可以防止人们
不得不进行额外的点击。 / p>

When possible, allow people to close one popover and open a new one with one tap. This behavior is especially desirable when several different bar buttons each open a popover, because it prevents people from having to make extra taps.

我现在能想到的唯一解决方案是在解雇弹出窗口时跟踪触摸位置并检查是否是另一个按钮。
有没有更简单的方法呢?

The only solution I can think right now is to track the position of the touch when dismissing the popover and check whether that was the position of another button. Is there any easier way to do this?

PS:我在stackoverflow中搜索并在发布之前用Google搜索了一段时间。对不起,如果之前有人问这个。

PS: I searched in stackoverflow and googled quite a while before posting. Sorry, if this was asked here before.

更新

我想我没有解释好自己。假设我有三个按钮。所有人都打开了一个弹出窗口。我的用户点击按钮#1并打开一个弹出窗口。当弹出窗口打开时,用户点击按钮#2。 popover被解雇(因为用户点击了popover之外 - 非模态弹出窗口的默认行为)并且因为用户点击了按钮#2而打开了新的弹出窗口。所有这些都不需要点击两次:一次解除弹出窗口,两次打开新的弹出窗口。

I guess I didn't explain myself well. Let's say I have three buttons. All of them open a popover. My user taps button #1 and a popover opens. While the popover is open, the user taps button #2. The popover gets dismissed (because the user tapped outside of the popover - default behavior of non-modal popovers) and a new popover opens up because the user had clicked on button #2. All of that without having to tap twice: once to dismiss the popover and twice for opening the new one.

第二次更新

我建造了一个简单的假人来重现我正在尝试做的事情。当用户点击按钮并打开弹出窗口时,不会调用打开弹出窗口的方法。因此,用户必须单击两次才能打开第二个弹出窗口。有什么想法吗?

I built a simple dummy to reproduce what I'm trying to do. When the user taps on a button and a popover is open, the method that opens the popovers doesn't get called. Therefore the user has to click twice to open the second popover. Any ideas?

#import "RootViewController.h"
#import "AViewController.h"

@interface RootViewController() 

@property (nonatomic, retain) UIPopoverController *currentPopover;

@end

@implementation RootViewController

@synthesize currentPopover;

- (void)loadView
{
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
    UIView *view = [[UIView alloc] initWithFrame:applicationFrame];

    CGRect buttonFrame = CGRectMake(50, 100, 200, 40);

    for (int i = 0; i < 3; i++) 
    {

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setTitle:[NSString stringWithFormat:@"Button %i", i + 1] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(openPopover:) forControlEvents:UIControlEventTouchDown];
        [button setFrame:buttonFrame];
        [view addSubview:button];

        buttonFrame.origin.y += 50;
    }


    self.view = view;
    [view release];
}

- (IBAction)openPopover:(id)sender
{
    AViewController *avc = [[AViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:avc];
    [avc release];

    UIPopoverController *tempPopover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
    [tempPopover setDelegate:self];
    [tempPopover setPopoverContentSize:CGSizeMake(320, 500)];
    [tempPopover presentPopoverFromRect:[sender frame] inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

    self.currentPopover = tempPopover;
    [tempPopover release];


    [navigationController release];
}

- (void)dealloc
{
    [currentPopover release];
    [super dealloc];
}

@end


推荐答案

如果在工具栏中使用条形按钮项,则当您点击另一个条形按钮项时,打开的弹出窗口会自动关闭。在这些情况下,您应该关闭可见的弹出框并一步打开另一个。

If you use bar button items in a toolbar, the open popover is not automatically closed when you tap another bar button item. In these situations you should close the visible popover and open the other one in one step.

这篇关于关闭Popover并点按一下即可打开新的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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