![](/img/trans.png)
[英]Why is -animateWithDuration:delay:options:animations:completion: blocking the UI?
[英]animateWithDuration:delay:options:animations:completion: not working (strangely)
我正在嘗試使用以下代碼將UIView轉換一段距離:
CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(@"Begin!");
CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
[self.exposureHintView setTransform:newTrans];
}
completion:^(BOOL finished) {
NSLog(@"End %d", finished);
}];
因此,基本上,我只是想將視圖從某個角度(-100, -100)
例如, (-100, -100)
到相對於其應處於(0, 0)
。
由於一旦視圖出現就想對其進行動畫處理,因此我將代碼放入viewDidAppear:
。 但是,當我運行代碼時,什么也沒發生。
這里的self.exposureHintView
是UIView
的自定義子類,這有關系嗎?
為什么?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[_AboutView setFrame:CGRectMake(0, 0, 320, 510)];
[UIView commitAnimations];
使用此代碼更改視圖的位置
我認為這里的問題是,您在情節提要或XIB文件中創建了無需編程即可創建的暴露提示視圖。
嘗試執行以下操作:
- (void)viewDidLoad
{
//Init exposureHintView
UIView* exposureHintView = [[UIView alloc]initWithFrame(sampleFrame)];
[self addSubView: exposureHintView];
//Set transform
CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
//Commit animation
[UIView animateWithDuration:2.0 delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(@"Begin!");
CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
[self.exposureHintView setTransform:newTrans];
}
completion:^(BOOL finished) {
NSLog(@"End %d", finished);
}];
原因是您在使用情節提要或XIB時無法在>> ViewDidLoad中設置此UIView的Frame或Transform或其他屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.