亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

效果出來了 但是tabbar感覺是整體下移了一些位置,咋整?

效果出來了 但是tabbar感覺是整體下移了一些位置,咋整?

iOS
嚕嚕噠 2023-04-15 18:14:34
最近剛學習IOS,現有一個登陸界面,還有一個包含多個選項卡的界面在點擊登陸界面的登陸按鈕時跳轉至含tabbar的界面,我該怎么實現了?希望有人能給出思路,如果有關鍵代碼最好了在ViewController.m中登陸按鈕的代碼如下UIViewController *controller=[[Tabbarcontroller alloc]init];[self presentModalViewController:controller animated:YES];在TabbarController.h中@property(strong,nonatomic) UITabBarController *controller;然后是在TabbarController.m中的@synthesize controller;-(id) initWithNibName(NSString *)nibNameOrNil bundle:(NSBundle *)nibBoundleOrNil {    self=[super initWithNibName:nibNameOrNil bundle:nibBoundleOrNil];    UIViewController *first=[[First alloc]initWithNibName:@"First" bunlde:nil];    UIViewController *second=[[Second alloc]initWithNibName:@"Second" bunlde:nil];     controller=[[UITabBarController alloc]init];     controller.viewControllers=[NSArray arrayWithObjects:first,second,nil];     [self.view addSubView:controller.view];    if(self){     }    return self; }效果出來了 但是tabbar感覺是整體下移了一些位置(頭部有一些空白,tabbar選項卡底部被遮蓋了)
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

簡單實現方法:你的項目建立在tabbarcontroller的基礎上。
在appdelegate的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

方法中,使用

[self.tabBarController presentModalViewController:loginNC animated:NO];

這樣,你打開程序,首先顯示的登陸頁面,點擊登陸,在登陸的事件中加上下述代碼

[self dismissModalViewControllerAnimated:YES];

這樣就實現了你想要的效果。

稍微麻煩點的方法:你的項目建立在singleview的基礎上(單一viewController)。再寫一個otherTabBarController,

UIViewController *vc1 = [[[UIViewController alloc] init] autorelease];
vc1.view.backgroundColor = [UIColor redColor];UIViewController *vc2 = [[[UIViewController alloc] init] autorelease];
vc2.view.backgroundColor = [UIColor blueColor];

[self setViewControllers:[NSArray arrayWithObjects:vc1,vc2, nil]];

點擊登陸就使用

[viewController presentModalViewController:otherTabBarController animated:YES];

otherTabBarController要繼承自UITabBarController,這樣就沒有底部擋住的問題。

最初我給的答案是使用繼承自UIViewController的方法。
不過我覺得這樣寫的代碼層次會有些冗余。不如直接繼承自UITabbarController作為容器。

用系統的tabbarcontroller會擋住,至于原因因為系統的這套TabBarController.view的尺寸是320*480,而默認建立的singleview項目,是有statusBar的20像素存在,這樣,viewController的尺寸是320*460,而在這個的基礎上addSubview的尺寸(320*480)大于本身,自然按照左上角對齊,就導致向下偏移20像素。

當然你也可以在AppDelegate的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

中加上

[[UIApplication sharedApplication] setStatusBarHidden:YES];

解決偏移的問題。


查看完整回答
反對 回復 2023-04-18
  • 1 回答
  • 0 關注
  • 178 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號