IOS 登陆判断问题
有一个登陆界面,还有一个包含多个选项卡的界面在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选项卡底部被遮盖了)
这个是什么原因呢?
简单实现方法:你的项目建立在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];
相关推荐
- iOS集成丁香园DXY OAuth 登陆 swift代码示例
- this.CHKPower.SelectedValue="1,20," checkboxlist在判断选定有关问题
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内
- 关于在一定时间内限制登陆次数的有关问题
- .net项目登陆有关问题,请高手帮忙啊
- linux高手!redhat6.2登陆有关问题
- Ubuntu root登陆的有关问题
- 请问一个模拟登陆的有关问题!求高手帮忙!
- IOS判断手机型号
- ios 静态库crash有关问题
- Asp.net useful tools
- VC++菜单 2.1 如何动态添加和删除菜单项 2.2 如何在系统菜单中添加菜单项 2.3 如何禁用关闭按钮 2.4 如何启用和禁用菜单项 2.5 如何设置菜单项的检查状态 2.6 如何实现快捷菜单