码迷,mamicode.com
首页 > 其他好文 > 详细

NavigationBar的透明效果

时间:2015-07-15 15:22:24      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

@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;
                
//            }];
            
        }
    }
}


技术分享






NavigationBar的透明效果

标签:

原文地址:http://my.oschina.net/wupengnash/blog/478824

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!