刚学flutter,对TabController的使用很迷茫,按照官网的描述做了,但是出现错误,不知道怎么解决。
我只想在更改选项卡时更改标题并从应用栏引导。
final List<ChangeTitleAndLeading> _data = [
new ChangeTitleAndLeading(title: "Home", leading: Icon(Icons.home)),
new ChangeTitleAndLeading(title: "Profile", leading: Icon(Icons.person)),
new ChangeTitleAndLeading(title: "Friends", leading: Icon(Icons.people))
];
ChangeTitleAndLeading _handler;
TabController _controller;
@override
void initState() {
super.initState();
_checkEmailVerification();
_controller = TabController(vsync: this, length: 3);
_handler = _data[0];
_controller.addListener(_handleSelected);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void _handleSelected() {
setState(() {
_handler = _data[_controller.index];
});
}
return MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.teal,
),
home: new Scaffold(
appBar: new AppBar(
leading: Icon(Icons.home),
title: new Text("Home"), …Run Code Online (Sandbox Code Playgroud) 如何TabView在SwiftUI中为选中的Tabbar项目设置动画?
例如,给选定的项目一个.scaleEffect()带有.spring()动画或某物的内容,如下所示:
到目前为止,这是我尝试过的:
struct MyTabbedView: View {
@State var enlargeIt1 = false
@State var enlargeIt2 = true
var body: some View {
TabView {
Text("Item 1")
.onAppear {
self.enlargeIt1.toggle()
self.enlargeIt2.toggle()
}
.tabItem{
VStack{
Image(systemName: "music.note")
.font(self.enlargeIt1 ? .system(size: 30) : .system(size: 15) )
.animation(.interpolatingSpring(mass: 0.7, stiffness: 200, damping: 10, initialVelocity: 4))
Text("Music")
}
}.tag(1)
Text("Item 2")
.onAppear {
self.enlargeIt1.toggle()
self.enlargeIt2.toggle()
}
.tabItem{
VStack{
Image(systemName: "music.mic")
.font(self.enlargeIt2 ? .system(size: 30) : .system(size: 15) )
.animation(.interpolatingSpring(mass: …Run Code Online (Sandbox Code Playgroud) 我在从 Xcode 11 编译时遇到了 iOS13 的 tabBar 标题问题。它在从 Xcode 10 编译时完美运行。请找到问题的屏幕截图,下面是自定义 tabBar 的代码。
代码是
self.tabBar.isTranslucent = true
self.tabBar.tintColor = UIColor.white
UITabBarItem.appearance().badgeColor = Constant.Colors.colorFF1744
if #available(iOS 13, *) {
let appearance = UITabBarAppearance.init()
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size: Constant.FontSize.P5heading)!,NSAttributedString.Key.foregroundColor:Constant.Colors.color8D8D8D]
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size:Constant.FontSize.P5heading)!,NSAttributedString.Key.foregroundColor:Constant.Colors.colorFF1744]
appearance.stackedItemPositioning = .automatic
self.tabBar.standardAppearance = appearance
} else {
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size: Constant.FontSize.P5heading)!, NSAttributedString.Key.foregroundColor:Constant.Colors.color8D8D8D], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size: Constant.FontSize.P5heading)!, NSAttributedString.Key.foregroundColor:Constant.Colors.colorFF1744], for: .selected)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用基于选项卡栏的应用程序,并且在详细信息屏幕上选项卡栏被隐藏。问题是当选项卡栏隐藏时,它仍然会占据选项卡栏的空白区域并且safeAreaLayoutInsets不会更新。当方向改变或从背景移动到前景时,它会起作用。
self.tabBarController.tabBar.hidden = YES;
Run Code Online (Sandbox Code Playgroud)
查看层次结构
UITabbarController
|--UISplitViewController
|--UIViewController (first VC)
|--UINavigationController
|--UIViewController (second VC)
Run Code Online (Sandbox Code Playgroud)
该问题与Apple 论坛中报告的问题类似
我有一个iPhone应用程序:当你打开应用程序时,你会看到"LoginView".如果您登录到应用程序,您会看到一个TabBarController.在第三个和最后一个选项卡中有"注销"按钮.如果单击,则会再次看到"LoginView".我的问题是,如果你再次登录,你会看到"旧"标签栏,所选标签是第三个,而不是一个标签,并且有一个"退出"按钮.此外,如果用户使用其他用户登录,请查看上一个用户的旧数据(非常危险).
这是代码: - Delegate.h:
UITabBarController *tabBarController;
LoginViewController *loginView;
Run Code Online (Sandbox Code Playgroud)
- Delegate.m(didFinishLaunchingWithOptions):
[self.window makeKeyAndVisible];
loginView = [[LoginViewController alloc] init];
if (YES) { /* if the user is not already logged */
[self.window addSubview:loginView.view];
}
Run Code Online (Sandbox Code Playgroud)
Delegate.m(方法):
- (void)loginComplete {
[loginView dismissModalViewControllerAnimated:YES];
[window addSubview:tabBarController.view];
}
- (void)logoutComplete {
[[tabBarController view] removeFromSuperview];
[tabBarController release];
[window addSubview:loginView.view];
}
Run Code Online (Sandbox Code Playgroud)
这是两个不同viewcontrollers中的两种方法:
- (IBAction)login:(id)sender {
TabNavisAppDelegate *delegate =
(TabNavisAppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate loginComplete];
}
Run Code Online (Sandbox Code Playgroud)
(注销方法是一样的)
伙计们,我该如何解决这个痛苦的问题呢?所以,这里有一个我想要的应用程序列表:"Foursquare","Brightkite"等.每个人都有一个登录屏幕,一个标签栏视图和一个注销按钮.
感谢大家.
我正在使用TabBar应用程序.在一个视图中有一个UISearchBar,当按下时,键盘出现.
问题是键盘隐藏了标签栏.
你知道怎么解决吗?
我在其中创建了一个tabBar并设置了图像,但是在它下方留下了太多的空间tabBarItem.我怎么能删除它?
这是我tabBar现在的显示

我想像这样展示它

显示Tabbar
firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
thirdVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
forthVC = [[ForthViewController alloc] initWithNibName:@"ForthViewController" bundle:nil];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstVC,secondVC,thirdVC,forthVC, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:NO];
[self.window addSubview:self.tabController.view];
//self.tabController.selectedIndex = 1;
self.tabController.delegate = self;
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
对于tabBar背景图片我使用了这段代码
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarimg1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
Run Code Online (Sandbox Code Playgroud)
并设置img项目我已使用此代码
//used to set the …Run Code Online (Sandbox Code Playgroud) 我有一个iOS 7应用程序,在TabbarController中有一个NavigationController.然后我自定义条形背景颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]];
Run Code Online (Sandbox Code Playgroud)
它运行正常.但如果有一个ViewController想要不被酒吧覆盖的话,就像这样
self.edgesForExtendedLayout = UIRectEdgeTop;
Run Code Online (Sandbox Code Playgroud)
这意味着这个ViewController不希望被Tabbar覆盖.但它使Tabbar 比正常更暗
我想这是因为我为酒吧使用自定义颜色.怎么修 ?
我们试图将标签栏图标居中到标签栏中心,因为我们不希望在下面显示文本.因此图标应该是单独的并且在标签栏中居中.这就是他们现在的样子.标签栏控制器不是根视图控制器,因此我们无法使用rootviewcontroller直接访问它,因为我们在那里找到了很多响应.有任何想法吗?我们变得疯狂......
我正在尝试使用颤振在屏幕中央创建一个标签栏,同时尝试它我在列中提供了 TabBarView 并且我陷入了这个错误。请解决这个问题。
I/flutter ( 3983): ??? EXCEPTION CAUGHT BY RENDERING LIBRARY ??????????????????????????????????????????????????????????
I/flutter ( 3983): The following assertion was thrown during performResize():
I/flutter ( 3983): Horizontal viewport was given unbounded height.
I/flutter ( 3983): Viewports expand in the cross axis to fill their container and constrain their children to match
I/flutter ( 3983): their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
I/flutter ( 3983): vertical space in which to …Run Code Online (Sandbox Code Playgroud)