蘋果「手機人機界面指南」說,關於Popovers:關閉酥料餅和開放的新的一個水龍頭
如果可能的話,讓人們接近一個酥料餅,並打開一個新的 用一個水龍頭。當多個 不同的酒吧按鈕每個都打開一個彈出窗口時,這種行爲是特別需要的,因爲它可以防止人們不得不進行額外的點擊。
我現在唯一能想到的解決方案就是在解除彈出窗口時跟蹤觸摸的位置,並檢查是否是另一個按鈕的位置。 有沒有更簡單的方法來做到這一點?
PS:我在stackoverflow中搜索並搜索了很長時間才發佈。對不起,如果這是之前在這裏問過。
UPDATE
我想我沒有解釋自己很好。假設我有三個按鈕。他們都打開了一個popover。我的用戶點擊按鈕#1,彈出窗口打開。當彈出窗口打開時,用戶點擊按鈕#2。彈出窗口被取消(因爲用戶在彈出窗口之外輕敲 - 非模式彈出窗口的默認行爲),並且由於用戶點擊了按鈕#2,新的彈出窗口打開。所有這一切都無需點擊兩次:一次解散流行和兩次打開新的。
月2日更新
我建了一個簡單的虛擬重現我想要做的事。當用戶點擊按鈕並且彈出窗口打開時,打開彈出窗口的方法不會被調用。因此用戶必須點擊兩次以打開第二個彈出窗口。有任何想法嗎?
#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
我沒有使用工具欄,而是一堆UIButtons。它是一樣的嗎?這很奇怪。我的餡餅行爲有所不同。 – strave
是的,它的行爲不同。如果你不使用工具欄,你就沒有這個問題。您可以輕鬆地爲自己嘗試,將兩個UIBarButtonItems放在工具欄中,這兩個都會打開一個彈出窗口。如果您按下第二個按鈕,則第一個彈出窗口不*關閉(儘管輕擊在第一個彈出窗口之外)。在這些情況下,你必須做你自己的popover管理。 – Tom
但由於我沒有使用工具欄,我沒有那個「問題」。不過,我很樂意有這個問題。在這種情況下,我可以關閉popover並打開一個新的。就我而言,彈出窗口打開時,我似乎沒有爲按鈕獲取任何觸摸事件。你可以檢查我剛發佈的代碼。 – strave