操作表的最后一个按钮没有被点击

发布于 2024-10-07 20:25:48 字数 189 浏览 2 评论 0原文

我在我的项目中使用了一个操作表,当它出现时,它显示所有按钮,但最后一个(第四个)按钮没有响应我的点击(只有一半响应)。

我知道原因是因为我使用了 TabBarController 和当前的类位于该选项卡栏控制器内...... 只有操作表的那部分在选项卡上方有响应......而我的最后一个按钮一半在上面,一半在选项卡栏顶部,

请帮忙

I have used an actionsheet in my project and when it appears it show all buttons but last (4th) button does not responds to my click(only it's half part responds)..

I know the reason it is because i have used a TabBarController and the present class is inside that tabbar controller....
only that part of the actionsheet is responding which is above the tabs....and my last button is half above and half is on top of tabbar

please help

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

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

发布评论

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

评论(3

红焚 2024-10-14 20:25:48

我建议使用这个:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

我遇到了与您相同的问题,并使用此方法来证明它对我有用。 TabBar 希望成为关键窗口,这使得底部按钮出现在上方,但实际上位于选项卡栏下方。

希望这对您有用。

编辑

如果您使用横向模式并且上述方法不起作用。您可以使用以下修复:

@Vinh Tran:[sheet showFromTabBar:self.parentViewController.tabBarController.tabBar]

i suggest using this:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

I had the same problem that you have and using this method to show it worked for me. The TabBar wants to stay key Window what makes your bottom button appear above, but is actually under the tabbar.

Hope this does the trick for you..

Edit

If you use landscape mode and the method above doesn't work. You can use the following fix:

@Vinh Tran: [sheet showFromTabBar:self.parentViewController.tabBarController.tabBar]

残龙傲雪 2024-10-14 20:25:48

您使用什么方法来显示您的操作表。尝试 showFromTabBar: 方法

What method do you use to show your actionsheet. Try showFromTabBar: method

ゝ杯具 2024-10-14 20:25:48

当您的界面旋转为横向并且父视图控制器对其进行转换时,真正的问题就出现了。相信我,这是一个现实的场景,doh。然后操作表被剪裁,并且您不能使用parentViewController,因为它被转换了。避免所有这些问题的解决方案是创建一个新窗口,添加一个可旋转视图控制器作为 rootViewController 并使用其视图来显示工作表。

CGRect applicationRect = [[UIScreen mainScreen] bounds];
UIWindow* actionSheetWindow = [[UIWindow alloc] initWithFrame:applicationRect];
RotationViewController* rootViewController = [[RotationViewController alloc] initWithNibName:nil bundle:nil];
actionSheetWindow.rootViewController = rootViewController;
[rootViewController release];
actionSheetWindow.hidden = NO;

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil];
[actionSheet setCancelButtonWithTitle:@"Cancel" handler:^{
    actionSheetWindow.hidden = YES;
    [actionSheetWindow release];
}];

[actionSheet showInView:rootViewController.view];

上面的代码使用了 BlocksKit,但您也可以使用 actionSheet 委托和实例属性来完成此操作。

RotationViewController 只是一个 UIViewController 子类,它实现了

- (void) viewDidLoad {
   [super viewDidLoad];
   self.view.backgroundColor = [UIColor clearColor];
   self.view.opaque = NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return YES;
}

The real problem comes in, when your interface is rotated to landscape and the parent view controller has a transformation on it. Believe me, that's a realistic scenario, doh. Then the action sheet is clipped and you can't use the parentViewController because it is transformed. The solution to avoid all these issues is to create a new window, add a rotatable view controller as rootViewController and use its view to display the sheet.

CGRect applicationRect = [[UIScreen mainScreen] bounds];
UIWindow* actionSheetWindow = [[UIWindow alloc] initWithFrame:applicationRect];
RotationViewController* rootViewController = [[RotationViewController alloc] initWithNibName:nil bundle:nil];
actionSheetWindow.rootViewController = rootViewController;
[rootViewController release];
actionSheetWindow.hidden = NO;

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil];
[actionSheet setCancelButtonWithTitle:@"Cancel" handler:^{
    actionSheetWindow.hidden = YES;
    [actionSheetWindow release];
}];

[actionSheet showInView:rootViewController.view];

The code above uses BlocksKit, but you can do it also by using the actionSheet delegate and instance properties.

RotationViewController is just a UIViewController subclass that implements

- (void) viewDidLoad {
   [super viewDidLoad];
   self.view.backgroundColor = [UIColor clearColor];
   self.view.opaque = NO;
}

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