所以我有一个标签栏应用程序,我放了一个像tweeter的效果,当你从标签栏按下一个按钮,箭头滑动到所选按钮,这是一个非常酷的“动画” 但问题是这个箭头总是在我的第一个计划中,当(例如)我想要全屏播放视频时箭头已经存在,当我切换到没有任何标签栏的其他视图时,箭头仍然存在......
我的代码在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;
}
我认为这就是全部 感谢帮助我,因为我真的不知道该怎么做..
答案 0 :(得分:0)
我确定它不是你想知道的,但这里已经是http://www.cocoacontrols.com/platforms/ios/controls/bctabbarcontroller的源代码
否则,如果您想调整自己的逻辑,则需要隐藏特定更改的图像视图,例如打开全屏电影。
答案 1 :(得分:0)
或者在UITabBarController
课程中尝试此操作:
- (void)hideTabBar
{
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
view.hidden = YES;
break;
}
}
}