NavigationBar的透明效果

@interface AppDelegate () <UINavigationControllerDelegate>
@property (nonatomic,strong) MyNavigationbar *mynavbar;
@property (nonatomic,strong) UINavigationController *nav;
@property (nonatomic,strong) UIViewController *onevc;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    _onevc = [[UIViewController alloc] init];
     _mynavbar= [[MyNavigationbar alloc] initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width, 64)];
    
    _nav = [[UINavigationController alloc] initWithRootViewController:_onevc];
    [self.nav setValue:_mynavbar forKey:@"navigationBar"];
    self.window.rootViewController = self.nav;
    [_mynavbar setBackgroundImage:[UIImage imageNamed:@"1"] forBarMetrics:UIBarMetricsDefault];

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    UIColor *color = [UIColor whiteColor];
    NSDictionary *dict = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
    
    self.nav.delegate = self;
    [self.nav.navigationBar setTitleTextAttributes:dict];
    _onevc.title = @"hahah";
    [self.window makeKeyAndVisible];
    
    return YES;
}
//-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
//{
//    
//   
//}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *tou = [touches anyObject];
    CGPoint loc = [tou locationInView:_onevc.view];
    CGPoint pre = [tou previousLocationInView:_onevc.view];
    CGFloat dir = (loc.y - pre.y);
   if (dir < 0)
   {
       float locPer = 1 - (loc.y / self.window.bounds.size.height);
       [self changeAlpha:locPer];
       NSLog(@"%f",locPer);
   }
    else
    {
        float locPer = 1 - (loc.y / self.window.bounds.size.height);
        NSLog(@"%f",locPer);
        [self changeAlpha:locPer];
    }
    
}
-(void)changeAlpha:(float)alphafloat
{
    for (UIView *view in self.mynavbar.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
//            [UIView animateWithDuration:2 animations:^{
            
                view.alpha = alphafloat;
                
//            }];
            
        }
    }
}


142811_1R0I_2370932.png






转载于:https://my.oschina.net/wupengnash/blog/478824

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值