【发布时间】:2011-08-05 13:37:47
【问题描述】:
所以我有一个标签栏应用程序,并且我设置了类似高音扬声器的效果,当您从标签栏按下按钮时,箭头滑动到所选按钮,这是一个非常酷的“动画” 但问题是这个箭头总是在我的第一个计划中,当(例如)我想全屏播放视频时,箭头已经存在,当我切换到没有任何标签栏的其他视图时,箭头仍然存在...
我的代码在 AppDelegate 中。 在 .h 中我有:
AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIImageView *tabBarArrow;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) UIImageView *tabBarArrow;
- (CGFloat) horizontalLocationFor:(NSUInteger)tabIndex;
- (void) addTabBarArrow;
在我的 .m 中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
_tabBarController.delegate = self;
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self addTabBarArrow];
[self.window makeKeyAndVisible];
return YES;
}
-(void) addTabBarArrow {
UIImage* tabBarArrowImage = [UIImage imageNamed:@"Arrow.png"];
self.tabBarArrow = [[[UIImageView alloc] initWithImage:tabBarArrowImage] autorelease];
CGFloat verticalLocation = self.window.frame.size.height - _tabBarController.tabBar.frame.size.height
- tabBarArrowImage.size.height + 6;
tabBarArrow.frame = CGRectMake([self horizontalLocationFor:0], verticalLocation,
tabBarArrowImage.size.width, tabBarArrowImage.size.height);
[self.window addSubview:tabBarArrow];
}
-(void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
CGRect frame = tabBarArrow.frame;
frame.origin.x = [self horizontalLocationFor:_tabBarController.selectedIndex];
tabBarArrow.frame = frame;
[UIView commitAnimations];
}
-(CGFloat) horizontalLocationFor:(NSUInteger)tabIndex{
CGFloat tabItemWidth = _tabBarController.tabBar.frame.size.width / _tabBarController.tabBar.items.count;
CGFloat halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
return (tabIndex * tabItemWidth) + halfTabItemWidth;
}
我认为仅此而已 感谢帮助我,因为我真的不知道该怎么做..
【问题讨论】:
标签: iphone animation view sdk set