@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;
// }];
}
}
}
转载于:https://my.oschina.net/wupengnash/blog/478824