有一个登陆界面,还有一个包含多个选项卡的界面在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 登陆判断问题的更多相关文章

  1. iOS 登陆的实现四种方式

    iOS 登陆的实现四种方式 一. 网页加载: http://www.cnblogs.com/tekkaman/archive/2013/02/21/2920218.ht ml [iOS登陆的实现] A ...

  2. jQuery登陆判断简单实现代码

    登陆判断在实际应用中还是比较常见,在客户端执行判断可以减少服务器端的负担,感兴趣的朋友可以参考下 复制代码代码如下: <script src="jquery-1.9.1.js" ...

  3. iOS - 正则表达式判断邮箱、身份证..是否正确:

    iOS - 正则表达式判断邮箱.身份证..是否正确: //邮箱 + (BOOL) validateEmail:(NSString *)email {     NSString *emailRegex ...

  4. ios如何判断键盘是否已经显示

    ios如何判断键盘是否已经显示   在群里看到有人问:ios如何判断键盘已经显示在界面上. 其实这个解决很简单: 写一个单例来管理键盘的状态. 这个单例在初始化方法init种监听2个事件,分别是 UI ...

  5. iOS 登陆之使用ShareSDK

    0. 概述 登陆要使用ShareSDK,可以实现多社交平台账号登陆,短信验证,并且都是永久免费的. 网址:www.mob.com 1.iOS 登陆之界面设置

  6. iOS开发 判断当前APP版本和升级

    从iOS8系统开始,用户可以在设置里面设置在WiFi环境下,自动更新安装的App.此功能大大方便了用户,但是一些用户没有开启此项功能,因此还是需要在程序里面提示用户的 方法一:在服务器接口约定对应的数 ...

  7. IOS登陆+注册+抽奖+排行榜

    要求:三个页面(登录页面,pickerView页面,排行榜页面),pickerView页面是三个组件,每个组件显示0-9,点击按钮进行随机,获得的值存入排行榜,排行榜显示大于500的最高的10个分数和 ...

  8. iOS ----------各种判断

    iOS 判断数字 - (BOOL) deptNumInputShouldNumber:(NSString *)str { if (str.length == 0) { return NO; } NSS ...

  9. iOS:判断用户名是否以字母开头、手机号输入、邮箱是否正确的正则表达式

    新建一个字符串分类:NSString(Check),定义类方法更方便 .h文件 #import <Foundation/Foundation.h> @interface NSString ...

随机推荐

  1. SQL语法中的子查询Subqueries

    记一下样子. 明白它的应用场景. SELECT account_id, product_cd, cust_id, avail_balance FROM account WHERE open_emp_i ...

  2. hdu 2516 FIB博弈

    分析请看:cxlove #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  3. [Java][Weblogic] weblogic.net.http.SOAPHttpsURLConnection incompatible with javax.net.ssl.HttpsURLConnection解决办法

    更新20141120: 我始终对修改生产上weblogic上的配置文件这一方法心存担忧(生产上的服务器不允许随便修改,可能会影响到其他应用),所以想使用代码的方式解决此问题,在对方法一失败原因进行了进 ...

  4. ASP.NET MVC 4 WebAPI Simple Sample

    // Controllers.cs namespace Microshaoft.WebApi.Controllers { using Microshaoft.WebApi.Models; using ...

  5. Android LayoutInflater详解(转)

    在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...

  6. POJ 1655 Balancing Act 树的重心

    Balancing Act   Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. ...

  7. Java学习笔记(七)——对象

    一.类与对象 1.类的定义 类就是模型,确定对象将会拥有的特征(属性)和行为(方法). 2.类的特点 (1)类是对象的类型 (2)具有相同属性和方法的一组对象的集合. 3.对象的属性: 对象具有的各种 ...

  8. JVM内存配置详解

    前段时间在一个项目的性能测试中又发生了一次OOM(Out of swap sapce),情形和以前网店版的那次差不多,比上次更奇怪的是,此次搞了几天之后啥都没调整系统就自动好了,死活没法再重现之前的O ...

  9. Fragemnt和TextView的交互(TextView在LinearLayout中)

    import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android ...

  10. 《DSP using MATLAB》 示例Example4.1

    今天开始看第4章,从开始看这本书到现在,过去一个多月,收获不少,继续坚持.