2012-12-25 31 views
2

我花了一天的時間嘗試更好地理解動畫。 下一個代碼很好,隱藏了我的tabbar。問題是它會延伸每個靠近它的UIButton。在標籤欄上包含一個自定義按鈕。如果它觸及另一層圖像,它會拉伸它。任何想法如何修復代碼以避免這種情況?由於動畫導致圖像拉伸

- (void)hideTabBar:(UITabBarController *) tabbarcontroller 
    { 
[UIView animateWithDuration:0.3 
         delay:0.0f 
        options:UIViewAnimationCurveLinear 
       animations:^{ 
    for(UIView *view in tabbarcontroller.view.subviews) 
    { 
    if([view isKindOfClass:[UITabBar class]] || [view isKindOfClass:[UIImageView class]]) 
    { 
     [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; 
    } 
    else 
    { 
     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; 
    } 
    } 
       } 
       completion:nil]; 
} 

enter image description here

隱藏後:

enter image description here

+0

您應該繼續並更詳細地描述您實際需要的內容 - 有時快速繪製的圖像確實令人感到奇怪。 – Till

+0

新圖片已添加。回購將在幾秒鐘內添加。 – Segev

+0

已添加與該程序的鏈接。 – Segev

回答

1

這是一個UIButton而不是UIImageView。從截圖中可以明顯看出,它將會成爲這個按鈕的其他部分。

所以,你需要修改你,如果條件爲,

if([view isKindOfClass:[UIButton class]] || [view isKindOfClass:[UITabBar class]] || [view isKindOfClass:[UIImageView class]]) 

,然後設置框。同樣改變你的show方法。

+0

該解決方案有效,但是當我想再次顯示標籤欄時,中心按鈕不會回到相同的位置。編輯:當我點擊隱藏時,我可以看到中心按鈕與標籤欄一樣高。不知道爲什麼。 – Segev

+0

@Sha,這就是爲什麼我說,你需要在show方法中處理它。用if([view isKindOfClass:[UIButton class]]'添加一個if條件並相應地設置框架。 – iDev

+0

使用你的解決方案,我可以使用簡單的動畫而不用拉伸,所以我使用動畫來給按鈕一點點的提升現在它的工作方式很好,我可能會嘗試if條件修復只是爲了踢,謝謝! – Segev