我为iOS 7制作了一个新项目,只有一个VIEwController.这是故事板:
我在顶部添加了一个简单的UIVIEw,在它下面添加了一个UINavigationbar,以及一个带有剩余空间的大型UIVIEw.最后一个视图是您应该放置内容的位置.
现在这里是VIEwController代码:
VIEwController.h:
#import <UIKit/UIKit.h>@interface VIEwController : UIVIEwController@property (weak,nonatomic) IBOutlet UIVIEw *littleVIEw;@property (weak,nonatomic) IBOutlet UINavigationbar *navbar;@property (weak,nonatomic) IBOutlet UIVIEw *mainVIEw;- (IBAction)togglelittleVIEw:(ID)sender;@end
littleVIEw是状态栏后面的视图,navbar是导航栏,mainVIEw是内容视图,togglelittlevIEw链接到导航栏中的按钮.
VIEwController.m:
@implementation VIEwController { BOol isVisible; CGfloat statusbarOffset;}- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; // Setting initial values isVisible = YES; statusbarOffset = 20; // Adding a gesture recognizer to littleVIEw UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; tap.numberOfTapsrequired = 1; tap.numberOftouchesrequired = 1; [_littleVIEw addGestureRecognizer:tap];}// linked to the nav bar button- (IBAction)togglelittleVIEw:(ID)sender { // If littleVIEw is not on screen,show it before animation if (!isVisible) { _littleVIEw.hIDden = !_littleVIEw.hIDden; [[UIApplication sharedApplication] setStatusbarStyle:UIStatusbarStylelightContent]; } // Animate to the new frames [UIVIEw animateWithDuration:0.25 animations:^{ _littleVIEw.frame = CGRectOffset(_littleVIEw.frame,isVisible ? -(_littleVIEw.frame.size.height-statusbarOffset) : (_littleVIEw.frame.size.height-statusbarOffset)); _navbar.frame = CGRectMake(_navbar.frame.origin.x,_littleVIEw.frame.origin.y + _littleVIEw.frame.size.height,_navbar.frame.size.wIDth,_navbar.frame.size.height); CGfloat offSet = isVisible ? self.vIEw.frame.size.height - _navbar.frame.size.height + statusbarOffset : self.vIEw.frame.size.height - _navbar.frame.size.height - _littleVIEw.frame.size.height + statusbarOffset; _mainVIEw.frame = CGRectMake(_mainVIEw.frame.origin.x,_navbar.frame.origin.y + _navbar.frame.size.height,_mainVIEw.frame.size.wIDth,offSet); isVisible = !isVisible; } completion:^(BOol finished) { // If vIEw is not visible after animation,hIDe it if (!isVisible) { _littleVIEw.hIDden = !_littleVIEw.hIDden; [[UIApplication sharedApplication] setStatusbarStyle: UIStatusbarStyleDefault]; } }];}// Do stuff on tap-(voID)handleTap:(UIGestureRecognizer*)tap { [[[UIAlertVIEw alloc] initWithTitle:@"Test" message:@"You tapped !" delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil] show];}@end
警告
这段代码并不完美,但它基本上复制了你正在寻找的效果.你应该努力让它按照你的意愿行事.此外,这是在一个简单的UIVIEwController中实现的,没有嵌入UINavigationController,我手动添加了导航栏.此代码不适用于UItableVIEwController或嵌入UINavigationController的UIVIEwController.它不使用autolayout,你绝对应该在iOS 6/7下使用它.
这是gif预览:
总结以上是内存溢出为你收集整理的ios – 如何添加facebook messenger状态栏等按钮全部内容,希望文章能够帮你解决ios – 如何添加facebook messenger状态栏等按钮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)