Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

objective c - Present UIViewController above TabBar

I am using a TabBarController, and from one of the tabs, I want to present another UIViewController, while keeping the TabBar displayed.

If I simply present or push the view controller, it is displayed in full screen, above the TabBar.

What is the right way to solve this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assume ViewControllerA is a UIViewController of TabBarController. And the UIViewController you want to present is ViewControllerB

To push ViewControllerB, while keeping the TabBar displayed. Simply inside ViewControllerA you just need to call

ViewControllerB *vc = // Initialize ViewControllerB here
[self.navigationController pushViewController:vc animated:YES];

To present ViewControllerB

ViewControllerB *vc = Initialize ViewControllerB here
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:vc animated:YES completion:nil];

With presenting, make sure you set UIModalPresentationOverCurrentContext for modalPresentationStyle property of ViewControllerB. If not, it will present fullscreen, over the TabBar

For easier understanding, i created a demo repo, you can take a look.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...