图像始终位于第一个计划中的问题
所以我有一个标签栏应用程序,我放置了一个像高音扬声器的效果,当您从标签栏按下按钮时,箭头滑到所选按钮,这是一个非常酷的“动画” 但问题是这个箭头总是在我的第一个计划中,当(例如)我想全屏播放视频时,箭头已经在那里,当我切换到没有任何选项卡栏的其他视图时,箭头仍然在那里...
我的代码在 AppDelegate 中。 在 .hi 中有这样的内容:
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;
}
我认为仅此而已 感谢帮助我,因为我真的不知道该怎么做..
so I have a tab bar application and I have put a effect like tweeter, when you push a button from the tab bar, a arrow slide to the selected button, it's a really cool "animation"
But the problem is this arrow is always in my first plan, when (for example) I want to play a video in full screen the arrow is already there, to when i switch to an other view without any tab bar, the arrow still there...
My code is in the AppDelegate.
in the .h i have that:
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;
and in my .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;
}
I think thats all
thanks to help me because I really don't know how to do that..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确信这不是您想知道的,但这里已经有 http 的源代码://www.cocoacontrols.com/platforms/ios/controls/bctabbarcontroller
否则,如果您想调整自己的逻辑,则需要在特定更改(例如打开全屏电影)时隐藏图像视图。
I'm sure its not what you wanted to know but here is already a source code for that http://www.cocoacontrols.com/platforms/ios/controls/bctabbarcontroller
otherwise if you like to adapt your own logic you will need to hide the image view on specific changes like opening a full screen movie.
或者在您的
UITabBarController
类中尝试一下:Or try this in your
UITabBarController
class: