【问题标题】:Problem with an image that is always in the first plan始终在第一个计划中的图像存在问题
【发布时间】: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


    【解决方案1】:

    我确定这不是您想知道的,但这里已经是 http://www.cocoacontrols.com/platforms/ios/controls/bctabbarcontroller 的源代码

    否则,如果您想调整自己的逻辑,则需要在特定更改(例如打开全屏电影)时隐藏图像视图。

    【讨论】:

    • 是的,我会看到的,但全屏视频的问题是我使用的是移动版 YouTube,所以我没有任何代码..
    【解决方案2】:

    或者在你的 UITabBarController 课堂上试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 2017-10-24
      相关资源
      最近更新 更多