若隐若现navgationbar

//左边按钮
UIButton *buttonLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonLeft setFrame:CGRectMake(0, 0, 30, 40)];
[buttonLeft setTitle:@"变色" forState:0];
[buttonLeft setTitleColor:[UIColor whiteColor] forState:0];
[buttonLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
[buttonLeft addTarget:self action:@selector(buttonClickleft) forControlEvents:UIControlEventTouchUpInside];
[buttonLeft setBackgroundColor:[UIColor blackColor]];
UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc]  initWithCustomView:buttonLeft];
self.navigationItem.leftBarButtonItem = leftBarItem;

-(void)buttonClickleft{
UDNavigationController *nav = (UDNavigationController *)self.navigationController;
[nav setAlph];
}

//单独文件

import <UIKit/UIKit.h>

@interface UDNavigationController : UINavigationController{
BOOL _changing;
}
@property(nonatomic, retain)UIView *alphaView;
-(void)setAlph;
@end

import "UDNavigationController.h"

@implementation UDNavigationController
@synthesize alphaView;
-(id)initWithRootViewController:(UIViewController *)rootViewController{
self = [super initWithRootViewController:rootViewController];
if (self) {
CGRect frame = self.navigationBar.frame;
alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height+20)];
alphaView.backgroundColor = [UIColor blueColor];
[self.view insertSubview:alphaView belowSubview:self.navigationBar];
[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"bigShadow.png"] forBarMetrics:UIBarMetricsCompact];
self.navigationBar.layer.masksToBounds = YES;

}
return self;

}
-(void)setAlph{
if (_changing == NO) {
_changing = YES;
if (alphaView.alpha == 0.0 ) {
[UIView animateWithDuration:0.5 animations:^{
alphaView.alpha = 1.0;
} completion:^(BOOL finished) {
_changing = NO;
}];
}else{
[UIView animateWithDuration:0.5 animations:^{
alphaView.alpha = 0.0;
} completion:^(BOOL finished) {
_changing = NO;

        }];
    }
}

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容