2011-04-07 81 views
1

我試圖移動並調整標籤尺寸,但會發生什麼情況是標籤會立即調整大小然後移動到位置。我首先嚐試了註釋掉的lbl.frame行。接下來,我發現了這樣一個問題:iPad - 如何移動和調整標籤尺寸

How to animate while resizing UIView

並補充其他所有的代碼除了contentMode。這是我想要的,但標籤的字體沒有隨着標籤縮小而向下調整。 (我打勾調整以適應xib)。最後添加contentMode行給了我與原始框架行相同的結果 - 首先縮小它們的動畫。

lbl.contentMode = UIViewContentModeRedraw; 
    [UIView animateWithDuration:1.0 delay:0.0 
         options:(UIViewAnimationOptionAllowUserInteraction) 
        animations:^{ 
         //lbl.frame = CGRectMake(x, mStartingLine.frame.origin.y+mStartingLine.frame.size.height, 100, 100); 
         CGRect theBounds = lbl.bounds; 
         CGPoint theCenter = lbl.center; 
         theBounds.size.height = 100; 
         theBounds.size.width = 100; 
         theCenter.y = mStartingLine.frame.origin.y+mStartingLine.frame.size.height+50; 
         theCenter.x = x; 
         lbl.bounds = theBounds; 
         lbl.center = theCenter; 
        } 
        completion:nil 
    ]; 

回答

1

我懷疑自動文本調整大小功能不適用於Core Animation。

我會建議做的是將標籤設置爲最終尺寸(使用它的邊界),然後對其應用一個變形,將其縮小到它的起始尺寸。這些事情的最終效果是,它應該保持在相同的外觀尺寸。

最後,使用animateWithDuration:動畫:將視圖的變換設置回標識變換,以便它變成新的尺寸。

我不知道這會造成什麼畫圖工件 - 你必須嘗試一下。