2013-06-19 78 views
0

嘗試獲取移動和縮小標籤的基本動畫。如果標籤的框架大小沒有改變,動畫工作正常。但如果縮小框架只能畫出邊框。如果更改幀大小,IOS標籤動畫不會繪製標籤內部

您可以看到註釋行,如果切換下面的行可以正常工作,因爲只有標籤的邊框被繪製。這裏的ToFrame比FromFrame小。

[UIView animateWithDuration:1.5 animations: 
^{ 
    label = [[UILabel alloc] initWithFrame:fromFrame]; 
    [label setBackgroundColor:color]; 
    label.text = text; 
    label.layer.cornerRadius = 10; 
    label.layer.borderWidth = 4; 
    [self.view addSubview:label]; 
    label.adjustsFontSizeToFitWidth = true; 

    CGRect frame = label.frame; 
    //frame.origin.y = self.view.frame.size.height; 
    frame = toFrame; 
    label.frame = frame; 
} 
completion:^ (BOOL finished) 
{ 
    [label removeFromSuperview]; 
} 

]; 
+0

我無法重現該問題,我只是將您的代碼粘貼到測試項目中,並且工作正常。我做出的唯一更改(清晰)是文本,從框架到框架 – micantox

+0

問題在於您的註釋行。您嘗試將標籤的origin.y'移動到它的'superView'的末尾。你能告訴我你想對標籤的框架應用什麼改變嗎? – Geek

+0

從框架是類似於10,50,700,100 – ort11

回答

0

結束動畫標籤/視圖的圖像。這裏是代碼,也許會幫助別人。假設ARC和Quartz包含。

- (void) animateFromFrame:(CGRect)fromFrame toFrame:(CGRect)toFrame andView:(UIView*)view 
{ 
    UIGraphicsBeginImageContext(view.bounds.size); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    UIImageView* imageView = [[UIImageView alloc] initWithImage:image]; 

    imageView.frame = fromFrame; 
    imageView.layer.cornerRadius = 10; 
    imageView.layer.borderWidth = 4; 
    [self.view addSubview:imageView]; 

    [UIView animateWithDuration:1.0 delay:0.25 options:nil animations: ^{ imageView.frame = toFrame; } completion:^ (BOOL finished) { [imageView removeFromSuperview]; } ]; 
}