- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 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/
我想将照片数据从 Tabbarcontroller 中的一个 Viewcontroller(cameraVC) 传递到同一 Tabbarcontroller 中的另一个 Viewcontroller(
我需要加载选项卡栏项目。在这里,我需要不同标签中标签栏的不同背景颜色。我正在更改 didSelectItem 中的栏色调颜色。但它的背景颜色没有改变。加载标签栏时它工作正常。 这是我的代码 over
我想获取标签栏默认大小,但我在ViewController中没有任何tabBar,所以我没有使用self.tabBarController?.tabBar.frame.size.height . 我使
我有一个应用程序的想法,但在使用 Xcode 几个月后,我遇到了一个主要的设计问题。我想要这个: 但正如许多 ios 开发人员所知,在界面构建器中使用传统的标签栏只会创建单色、非轮廓、标签栏按钮,如下
我在我的应用程序上使用 TabBarController,在其中一个主视图 (aViewController) 中,我按下另一个 Controller (bViewController),并使用 se
我想在用户点击选项卡时切换选定的选项卡。假设我有两个选项卡并且显示第一个选项卡,那么点击第一个选项卡(以及点击第二个选项卡)应该会引导我进入第二个选项卡。我已经实现了一个自定义 UITabBarCon
我有一个带有 3 个选项卡的选项卡栏 Controller ,每个选项卡都有导航 Controller ,在每个导航 Controller 的 Root View Controller 上我想要选项卡
我正在编写一个 iPhone 应用程序,它类似于 5-6 级向下钻取应用程序。我几乎完成了我的应用程序的编写,现在提出了一个新要求,即从第三个屏幕开始添加一个 TabBar(JQuery 中的导航栏)
我正在使用 SWRevealViewController 作为侧边菜单。我的应用程序中还有一个标签栏 Controller 作为主视图。 在我的菜单中,我有“MenuItem”(显示MenuItemV
我正在通过 Storyboard 创建一个 TabBar Controller 应用程序。我正在使用 Storyboard 引用对象来链接第三个选项卡项的另一个 Storyboard 。它工作正常,但
TabBar 没有隐藏在推送的 ViewController 中,我使用下面的代码来隐藏 tabBar, tabBarController?.tabBar.isHidden = true
我目前有两个 View Controller ,一个是使用 imagePicker 拍照的 CameraViewController,另一个是显示一个人收到的所有照片消息的 PhotoInboxVie
我有一个包含 5 个项目的 UITabBarController。在其中一个 ViewController 上,我有一个按钮,我将其称为“开始”,所以当我按下开始时,我想插入另一个 ViewContr
我正在更改 setSelectionIndicatorImage,当我在 iOS 8 上运行应用程序时,我得到图像和 tabBar 的常规宽度之间的间距。有没有一种方法可以使标签栏的高度与 setSe
我想通过在图像上向左滑动从“正在显示”导航到“即将推出”,此外,我希望 Appbar 在我滑动时不要移动,但我认为只有标签栏和我不确定,如果您知道如何实现这一点,请提供一些建议 enter image
在我的项目中,我有一个 UITabBarController。在其中一个 ViewControllers 上我有一个按钮。当我单击此按钮时,一个新的 ViewController 将以模态方式呈现。
我是 iPhone 开发新手,多个 View (xib 或 nib)真的让我感到困惑。这就是我想要实现的目标...... 使用 TabBarControllerAppDelegate 有 5 个不同的
滚动到底部后如何修复 iOS 15 标签栏透明: 最佳答案 在 iOS 15 中,Apple 添加了 scrollEdgeAppearance用于在边缘滚动时配置标签栏外观的属性。 https://d
我尝试创建如下图所示的自定义标签栏: 下面是我得到的结果: 以下是我当前的代码: class CustomTabBarController: UITabBarController { over
Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( child: Colu
我是一名优秀的程序员,十分优秀!