[英]Add UIScrollView to UIView programmatically not work in viewDidLoad but work in viewDidAppear?
[英]UIView Animation at viewDidLoad/viewDidAppear?
我正在viewDidLoad或viewDidAppear方法中嘗試一個簡單的UIView動畫,但它沒有動畫。
UIImage *bluredScreenshot = [self.parentViewControllerScreenshot applyBlur];
[UIView transitionWithView:self.screenshotView duration:3.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.screenshotView.image = bluredScreenshot;
} completion:nil];
簡單的交叉溶解兩個圖像。 從viewDidLoad或viewDidAppear運行時,圖像會更改但不會設置動畫。
但是讓我說我按下一個按鈕后從一個方法運行動畫,它會動畫。 為什么? 似乎很奇怪。
是否可以從viewDidLoad方法中創建它? 你怎么解決這個問題?
謝謝。
當視圖加載時,您無法設置動畫,因為沒有任何動畫效果。 嘗試在viewdidapear:並且不要使用過渡
[UIView animateWithDuration:3.
delay:0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.screenshotView.image = bluredScreenshot;
}
completion:nil];
你需要淡入屏幕截圖。 如果您使用的是兩張圖像,則需要將一張圖像視圖放在另一張圖像上。 在viewDidAppear內部彈出:調用[super viewDidAppear:animated];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.screenshotView.frame];
[self.view addSubview:imageView];
[imageView setAlpha:0.0f];
imageView = blurredScreenshot;
[UIView animateWithDuration:0.3f animations:^{
[imageView setAlpha:1.0f];
} completion:^(BOOL finished){
self.imageView.image = blurredScreenshot;
[imageView removeFromSuperview];
}];
只是提醒一下,有時你的問題可能是由於沒有打電話引起的:
self.layoutIfNeeded()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.