图像始终位于第一个计划中的问题

发布于 2024-11-28 06:02:33 字数 2388 浏览 2 评论 0原文

所以我有一个标签栏应用程序,我放置了一个像高音扬声器的效果,当您从标签栏按下按钮时,箭头滑到所选按钮,这是一个非常酷的“动画” 但问题是这个箭头总是在我的第一个计划中,当(例如)我想全屏播放视频时,箭头已经在那里,当我切换到没有任何选项卡栏的其他视图时,箭头仍然在那里...

我的代码在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲在坟头点根烟 2024-12-05 06:02:33

我确信这不是您想知道的,但这里已经有 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.

屋檐 2024-12-05 06:02:33

或者在您的 UITabBarController 类中尝试一下:

- (void)hideTabBar
{
    for(UIView *view in self.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            view.hidden = YES;
            break;
        }
    }
}

Or try this in your UITabBarController class:

- (void)hideTabBar
{
    for(UIView *view in self.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            view.hidden = YES;
            break;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文