iPhone 操作表取消按钮仅响应触摸中心附近

发布于 2024-12-22 00:21:49 字数 1865 浏览 1 评论 0原文

我以前遇到过类似的情况,按钮仅响应其部分视图中的触摸。我发现具有透明区域的图像视图位于较高的 z 级别,这掩盖了发生重叠的触摸。这是由于在添加模糊视图之前将按钮添加为子视图。

就操作表而言,我认为它会处于高于其他任何内容的最高 z 级别。由于操作表刚刚初始化并显示,因此我无法看到有什么东西覆盖了按钮。

(无论如何,我只是将应用程序转换为通用应用程序,并在 iOS 4.3 和 5.0 中进行测试。iPad 上的操作表中没有取消按钮。在 iOS 4.3 上模拟 iPhone 时存在此问题和 5.0。)

我正在寻找有关导致问题的其他想法。

更新 下面是显示操作表的代码,

- (void) shareButtonPressed {

    SHKItem *item = [SHKItem larkspreeSearchResult:searchResult];
    item.image = eventImageRaw;

    // Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

    // Display the action sheet
    [actionSheet showInView:self.view];

}

因为这是一个子类操作表,所以来自 ShareKit 的这个代码也可能会有所帮助。

+ (SHKActionSheet *)actionSheetForType:(SHKShareType)type
{
SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
                                                      delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];
as.item = [[[SHKItem alloc] init] autorelease];
as.item.shareType = type;

as.sharers = [NSMutableArray arrayWithCapacity:0];
NSArray *favoriteSharers = [SHK favoriteSharersForType:type];

// Add buttons for each favorite sharer
id class;
for(NSString *sharerId in favoriteSharers)
{
    class = NSClassFromString(sharerId);
    if ([class canShare])
    {
        [as addButtonWithTitle: [class sharerTitle] ];
        [as.sharers addObject:sharerId];
    }
}

// Add More button
[as addButtonWithTitle:SHKLocalizedString(@"More...")];

// Add Cancel button
[as addButtonWithTitle:SHKLocalizedString(@"Cancel")];
as.cancelButtonIndex = as.numberOfButtons -1;

return [as autorelease];
}

showInView 方法尚未被重写。

I have encountered something like this before, where a button only responds to touches in part of its view. I found a image view with a transparent area was on a higher z-level, which obscured the touches where the overlap occurred. This was due to the button being added as a subview before the obscuring view was added.

In the case of an action sheet, I thought it would be at the highest z-level over anything else. Since the action sheet was just initialized and shown, there is no way that I can see that something is covering the button.

(For what it's worth, I just converted the app into a universal app, and am testing in both iOS 4.3 and 5.0. There is no cancel button in the action sheet on the iPad. This problem exists when simulating for iPhone for both iOS 4.3 and 5.0.)

I'm looking for other ideas as to what is causing the problem.

UPDATE
Here is the code to show the action sheet

- (void) shareButtonPressed {

    SHKItem *item = [SHKItem larkspreeSearchResult:searchResult];
    item.image = eventImageRaw;

    // Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

    // Display the action sheet
    [actionSheet showInView:self.view];

}

Since this is for a subclassed action sheet, this, right out of ShareKit, might be helpful, too.

+ (SHKActionSheet *)actionSheetForType:(SHKShareType)type
{
SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
                                                      delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];
as.item = [[[SHKItem alloc] init] autorelease];
as.item.shareType = type;

as.sharers = [NSMutableArray arrayWithCapacity:0];
NSArray *favoriteSharers = [SHK favoriteSharersForType:type];

// Add buttons for each favorite sharer
id class;
for(NSString *sharerId in favoriteSharers)
{
    class = NSClassFromString(sharerId);
    if ([class canShare])
    {
        [as addButtonWithTitle: [class sharerTitle] ];
        [as.sharers addObject:sharerId];
    }
}

// Add More button
[as addButtonWithTitle:SHKLocalizedString(@"More...")];

// Add Cancel button
[as addButtonWithTitle:SHKLocalizedString(@"Cancel")];
as.cancelButtonIndex = as.numberOfButtons -1;

return [as autorelease];
}

The showInView method has not been overridden.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韬韬不绝 2024-12-29 00:21:49

如果此视图控制器是配置了工具栏的 UINavigationController 或 UITabBarController 的一部分,则任何操作表都需要显示在父控制器的视图中。例如,[actionSheet showInView:self.navigationController.view];[actionSheet showInView:self.tabBarController.view];

If this view controller is part of a UINavigationController with a toolbar configured or a UITabBarController then any action sheet needs to be presented in the parent controller's view. For instance, [actionSheet showInView:self.navigationController.view]; or [actionSheet showInView:self.tabBarController.view];.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文