gpt4 book ai didi

ios - 为什么我的 TabBar 按钮在我第一次加载 View Controller 时被禁用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:09:36 27 4
gpt4 key购买 nike

我有一个 iPhone 应用程序,我可以在 2 个标签栏之间切换。问题是在我交换标签栏的 View 中,我的标签栏按钮仅在第一次加载 View 时被禁用(当调用 loadView 和 viewDidLoad 时)。换句话说,如果我导航到该 View ,则选项卡栏按钮将被禁用。如果我从该 View 导航到某个内容然后弹出,按钮将被启用。 View 生命周期调用的区别是:

工作 -加载 View viewDidLoadviewWillAppear查看是否出现

不工作 -viewWillAppear查看是否出现

现在交换在 viewDidAppear 中。如果我将交换放在 viewWillAppear 中,按钮可以正常工作,但 View Controller 会跳下,因为选项卡栏交换动画是在 View 转换动画期间完成的。

我的第一个猜测是某个 View 位于选项卡栏的顶部。我认为那不是真的。我打印了两种情况下的 View 层次结构,只有一点点不同。

这是工作场景的 View 层次结构:

<UIWindow: 0x5a4c7c0; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5a4ca30>>
| <UILayoutContainerView: 0x5a591b0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x5a59230>>
| | <UITransitionView: 0x5a59c00; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x5a59ca0>>
| | | <UIViewControllerWrapperView: 0x5a6e960; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x5a6e9e0>>
| | | | <UILayoutContainerView: 0x5a5bb70; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x5a5bbc0>>
| | | | | <UINavigationTransitionView: 0x5a5c290; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x5a19400>>
| | | | | | <UIViewControllerWrapperView: 0xaf01810; frame = (0 20; 320 460); layer = <CALayer: 0xaf01840>>
| | | | | | | <UIView: 0x5abcba0; frame = (0 0; 320 460); layer = <CALayer: 0x5a8ff50>>
| | | | | | | | <CaptureAuxMenu: 0x5ac6850; frame = (0 480; 320 49); layer = <CALayer: 0x5ac68e0>>
| | | | | | | | | <UIImageView: 0x5ac6a50; frame = (0 0; 320 49); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5ac6a80>>
| | | | | | | | | <UIButton: 0x5ac67c0; frame = (18 7; 80 31); opaque = NO; layer = <CALayer: 0x5ac6b80>>
| | | | | | | | | | <UIImageView: 0x5acf910; frame = (0 0; 80 31); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5acf940>>
| | | | | | | | | <UIButton: 0x5ac7ed0; frame = (116 7; 80 31); opaque = NO; layer = <CALayer: 0x5ac7b50>>
| | | | | | | | | | <UIImageView: 0x5acf890; frame = (0 0; 80 31); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5acf8c0>>
| | | | | | | | | <UIButton: 0x5ac91f0; frame = (285 10; 25 25); opaque = NO; layer = <CALayer: 0x5ac8e70>>
| | | | | | | | | | <UIImageView: 0x5acf810; frame = (0 0; 25 25); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5acf840>>

| | <UITabBar: 0x5a59560; frame = (0 431; 320 480); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x5a59600>>
| | | <UITabBarButton: 0x5a638f0; frame = (2 1; 60 479); opaque = NO; layer = <CALayer: 0x5a660a0>>
| | | | <UITabBarSelectionIndicatorView: 0x5a6e250; frame = (0 2; 60 475); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6e280>>
| | | | <UITabBarSwappableImageView: 0x5a662a0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a66360>>
| | | | <UITabBarButtonLabel: 0x5a63ba0; frame = (16 465; 28 13); text = 'string'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a63990>>
| | | <UITabBarButton: 0x5a660d0; frame = (66 1; 60 479); opaque = NO; layer = <CALayer: 0x5a674a0>>
| | | | <UITabBarSwappableImageView: 0x5a663c0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a66410>>
| | | | <UITabBarButtonLabel: 0x5a66cc0; frame = (16 465; 28 13); text = 'string'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a665e0>>
| | | <UITabBarButton: 0x5a65990; frame = (130 1; 60 479); opaque = NO; layer = <CALayer: 0x5a68140>>
| | | | <UITabBarSwappableImageView: 0x5a689c0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a68170>>
| | | | <UITabBarButtonLabel: 0x5a696b0; frame = (16 465; 28 13); text = 'string'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a68ba0>>
| | | <UITabBarButton: 0x5a68420; frame = (194 1; 60 479); opaque = NO; layer = <CALayer: 0x5a697d0>>
| | | | <UITabBarSwappableImageView: 0x5a6abf0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6ac40>>
| | | | <UITabBarButtonLabel: 0x5a6af20; frame = (8 465; 44 13); text = 'FRIENDS'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a678c0>>
| | | <UITabBarButton: 0x5a6a5a0; frame = (258 1; 60 479); opaque = NO; layer = <CALayer: 0x5a6b230>>
| | | | <UITabBarSwappableImageView: 0x5a6b9b0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6b260>>
| | | | <UITabBarButtonLabel: 0x5a677c0; frame = (8 465; 44 13); text = 'PROFILE'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6b3d0>>
| | <UIImageView: 0x5a6b850; frame = (0 480; 320 49); opaque = NO; tag = 89364833; layer = <CALayer: 0x5a6d200>>
| | | <UIButton: 0x5a6d580; frame = (0 0; 64 49); opaque = NO; layer = <CALayer: 0x5a6d660>>
| | | | <UIImageView: 0x5c35b20; frame = (0 0; 63 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35b50>>
| | | <UIButton: 0x5a63480; frame = (64 0; 64 49); opaque = NO; tag = 1; layer = <CALayer: 0x5a66170>>
| | | | <UIImageView: 0x5c35aa0; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35ad0>>
| | | <UIButton: 0x5a6da30; frame = (128 0; 64 49); opaque = NO; tag = 2; layer = <CALayer: 0x5a6dac0>>
| | | | <UIImageView: 0x5c35a20; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35a50>>
| | | <UIButton: 0x5a6dc60; frame = (192 0; 64 49); opaque = NO; tag = 3; layer = <CALayer: 0x5a6dcf0>>
| | | | <UIImageView: 0x5c359a0; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c359d0>>
| | | <UIButton: 0x5a6de90; frame = (256 0; 64 49); opaque = NO; tag = 4; layer = <CALayer: 0x5a6df20>>
| | | | <UIImageView: 0x5c358c0; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35970>>

这是失败场景的 View 层次结构:

<UIWindow: 0x5a4c7c0; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5a4ca30>>
| <UILayoutContainerView: 0x5a591b0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x5a59230>>
| | <UITransitionView: 0x5a59c00; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x5a59ca0>>
| | | <UIViewControllerWrapperView: 0x5a6e960; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x5a6e9e0>>
| | | | <UILayoutContainerView: 0x5a5bb70; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x5a5bbc0>>
| | | | | <UINavigationTransitionView: 0x5a5c290; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x5a19400>>
| | | | | | <UIViewControllerWrapperView: 0x5ae49f0; frame = (0 20; 320 411); layer = <CALayer: 0x5ae4870>>
| | | | | | | <UIView: 0x5abcba0; frame = (0 0; 320 411); layer = <CALayer: 0x5a8ff50>>
| | | | | | | | <CaptureAuxMenu: 0x5ac6850; frame = (0 480; 320 49); layer = <CALayer: 0x5ac68e0>>
| | | | | | | | | <UIImageView: 0x5ac6a50; frame = (0 0; 320 49); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5ac6a80>>
| | | | | | | | | <UIButton: 0x5ac67c0; frame = (18 7; 80 31); opaque = NO; layer = <CALayer: 0x5ac6b80>>
| | | | | | | | | | <UIImageView: 0x5acf910; frame = (0 0; 80 31); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5acf940>>
| | | | | | | | | <UIButton: 0x5ac7ed0; frame = (116 7; 80 31); opaque = NO; layer = <CALayer: 0x5ac7b50>>
| | | | | | | | | | <UIImageView: 0x5acf890; frame = (0 0; 80 31); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5acf8c0>>
| | | | | | | | | <UIButton: 0x5ac91f0; frame = (285 10; 25 25); opaque = NO; layer = <CALayer: 0x5ac8e70>>
| | | | | | | | | | <UIImageView: 0x5acf810; frame = (0 0; 25 25); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5acf840>>

| | <UITabBar: 0x5a59560; frame = (0 431; 320 480); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x5a59600>>
| | | <UITabBarButton: 0x5a638f0; frame = (2 1; 60 479); opaque = NO; layer = <CALayer: 0x5a660a0>>
| | | | <UITabBarSelectionIndicatorView: 0x5a6e250; frame = (0 2; 60 475); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6e280>>
| | | | <UITabBarSwappableImageView: 0x5a662a0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a66360>>
| | | | <UITabBarButtonLabel: 0x5a63ba0; frame = (16 465; 28 13); text = 'string'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a63990>>
| | | <UITabBarButton: 0x5a660d0; frame = (66 1; 60 479); opaque = NO; layer = <CALayer: 0x5a674a0>>
| | | | <UITabBarSwappableImageView: 0x5a663c0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a66410>>
| | | | <UITabBarButtonLabel: 0x5a66cc0; frame = (16 465; 28 13); text = 'string'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a665e0>>
| | | <UITabBarButton: 0x5a65990; frame = (130 1; 60 479); opaque = NO; layer = <CALayer: 0x5a68140>>
| | | | <UITabBarSwappableImageView: 0x5a689c0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a68170>>
| | | | <UITabBarButtonLabel: 0x5a696b0; frame = (16 465; 28 13); text = 'string'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a68ba0>>
| | | <UITabBarButton: 0x5a68420; frame = (194 1; 60 479); opaque = NO; layer = <CALayer: 0x5a697d0>>
| | | | <UITabBarSwappableImageView: 0x5a6abf0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6ac40>>
| | | | <UITabBarButtonLabel: 0x5a6af20; frame = (8 465; 44 13); text = 'FRIENDS'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a678c0>>
| | | <UITabBarButton: 0x5a6a5a0; frame = (258 1; 60 479); opaque = NO; layer = <CALayer: 0x5a6b230>>
| | | | <UITabBarSwappableImageView: 0x5a6b9b0; frame = (6 218; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6b260>>
| | | | <UITabBarButtonLabel: 0x5a677c0; frame = (8 465; 44 13); text = 'PROFILE'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5a6b3d0>>
| | <UIImageView: 0x5a6b850; frame = (0 480; 320 49); opaque = NO; tag = 89364833; layer = <CALayer: 0x5a6d200>>
| | | <UIButton: 0x5a6d580; frame = (0 0; 64 49); opaque = NO; layer = <CALayer: 0x5a6d660>>
| | | | <UIImageView: 0x5c35b20; frame = (0 0; 63 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35b50>>
| | | <UIButton: 0x5a63480; frame = (64 0; 64 49); opaque = NO; tag = 1; layer = <CALayer: 0x5a66170>>
| | | | <UIImageView: 0x5c35aa0; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35ad0>>
| | | <UIButton: 0x5a6da30; frame = (128 0; 64 49); opaque = NO; tag = 2; layer = <CALayer: 0x5a6dac0>>
| | | | <UIImageView: 0x5c35a20; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35a50>>
| | | <UIButton: 0x5a6dc60; frame = (192 0; 64 49); opaque = NO; tag = 3; layer = <CALayer: 0x5a6dcf0>>
| | | | <UIImageView: 0x5c359a0; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c359d0>>
| | | <UIButton: 0x5a6de90; frame = (256 0; 64 49); opaque = NO; tag = 4; layer = <CALayer: 0x5a6df20>>
| | | | <UIImageView: 0x5c358c0; frame = (0 0; 64 49); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x5c35970>>

在这两种情况下,我能看到的唯一明显区别是第 7 行和第 8 行。您会看到 UIViewControllerWrapperView 和子 UIView 有不同的框架,但我不太确定为什么这会成为一个问题,因为我不确定对应的 UIView 并且我找不到关于 UIViewControllerWrapperView 的任何文档。

我正在使用以下代码来交换标签栏:

- (void)viewDidAppear:(BOOL)animated{ 
[super viewDidAppear:animated];
[AppHelpers hideTabBarController:self.tabBarController withHidden:YES];
[self showCaptureTabBar];
}

+ (void) hideTabBarController:(UITabBarController *)tbc withHidden:(BOOL)hide {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

for(UIView *view in tbc.view.subviews)
{
if([view isKindOfClass:[UIImageView class]])
{
if (hide) {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
}else {
if (hide) {
// When hiding the tabbarcontroller, the view should be full height
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
} else {
// When showing the tabbarcontroller, the view needs to leave 49px of room for it at the bottom
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
}

[UIView commitAnimations];
}

- (void)showCaptureTabBar {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[captureTabBar setFrame:CGRectMake(captureTabBar.frame.origin.x, 412.0f, captureTabBar.frame.size.width, captureTabBar.frame.size.height)];
[UIView commitAnimations];
}

任何关于为什么可以禁用按钮以便我可以尝试其他调试的想法将不胜感激。有点撞墙了

最佳答案

如果您的包装器 View 较小,那肯定会导致问题。特别是当包装器小于其中的所有 UI 元素时。 UIView 仍然可以显示超出其框架的元素,但用户交互不会超出其框架。

要查看这是否是问题所在,请尝试在包装器上将“Clip Subviews”的属性设置为 YES,看看您是否仍然可以看到工具栏。如果您看不到工具栏,则应将包装器做得更大,以便整个工具栏可以进行用户交互。

关于ios - 为什么我的 TabBar 按钮在我第一次加载 View Controller 时被禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6343496/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com