标签:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotifications:) name:ZSYCurrentUserLoginStatusNotifyKey object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotifications:) name:ZSYTabbarWillHidenNotifyKey object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotifications:) name:ZSYTabbarWillShowNotifyKey object:nil]; }
- (void)didReceiveNotifications:(NSNotification *)sender { if (!_middleImage) { _middleImage = [UIImage imageNamed:@"camera_button_take.png"]; } if (!_middleButton) { [self addCenterButtonWithImage:[UIImage imageNamed:@"camera_button_take.png"] highlightImage:[UIImage imageNamed:@"tabBar_cameraButton_ready_matte.png"]]; } if ([sender.name isEqualToString:ZSYTabbarWillHidenNotifyKey]) { [self _hideTabBarMiddleButton]; } else if ([sender.name isEqualToString:ZSYTabbarWillShowNotifyKey]) { [self _showTabBarMiddleButton]; } }
- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self name:ZSYTabbarWillHidenNotifyKey object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:ZSYTabbarWillShowNotifyKey object:nil]; }
- (void)_showTabBarMiddleButton { @weakify(self); [UIView animateWithDuration:0.2f animations:^{ @strongify(self); CGRect frame = self.middleButton.frame; frame.origin.y = [UIScreen mainScreen].bounds.size.height - self.middleImage.size.height; self.middleButton.frame = frame; }]; }
- (void)_hideTabBarMiddleButton { @weakify(self); [UIView animateWithDuration:0.2f animations:^{ @strongify(self); CGRect frame = self.middleButton.frame; frame.origin.y = [UIScreen mainScreen].bounds.size.height; self.middleButton.frame = frame; }]; }
-(void) addCenterButtonWithImage:(UIImage*)buttonImage highlightImage:(UIImage*)highlightImage { UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height); [button setBackgroundImage:buttonImage forState:UIControlStateNormal]; [button setBackgroundImage:highlightImage forState:UIControlStateHighlighted]; CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height; if (heightDifference < 0) button.center = self.tabBar.center; else { CGPoint center = self.tabBar.center; center.y = center.y - heightDifference/2.0; button.center = center; } [button addTarget:self action:@selector(middleButtonDidClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; self.middleButton = button; }
标签:
原文地址:http://www.cnblogs.com/xiongzenghui/p/4626184.html