2011-08-05 37 views
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; 
} 

我認爲是所有 感謝幫助我,因爲我真的不知道該怎麼做..

回答

0

我敢肯定它,你想知道的不是,但這裏已經爲http://www.cocoacontrols.com/platforms/ios/controls/bctabbarcontroller

源代碼,否則,如果你喜歡,以適應您需要將自己的邏輯隱藏在特定更改(如打開全屏幕電影)的圖像視圖上。

+0

是的,我會看到,但與全屏視頻的問題是,我使用YouTube的移動版本,所以我沒有任何代碼對於.. – AlexF

+0

但是,是的,它真的不是我要找的.. – AlexF

0

或者在你UITabBarController類試試這個:

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