我正在嘗試動畫UIView左右滑動。我試過的是截取當前視圖的屏幕截圖,而不是更新視圖的屏幕截圖,同時更新視圖的屏幕內容,然後執行動畫。但屏幕截圖沒有顯示在屏幕上。這只是黑色,直到原始視圖滑回屏幕上。下面是我使用的代碼:左右滑動UIView
UIGraphicsBeginImageContext(self.view.window.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
iv.image = image;
[self.view.window insertSubview:iv aboveSubview:self.view];
self.view.frame = CGRectMake(-self.view.frame.size.width, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
iv.frame = CGRectMake(self.view.frame.size.width*2, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[self loadData];
self.view.frame = CGRectMake(0, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
} completion:NULL];
[iv removeFromSuperview];
[iv release];
你能發佈最終的代碼嗎?我遵循你的建議,但仍然遇到你描述的問題(截圖沒有出現)。 – user664939 2014-04-21 17:43:52
@ user664939我真的不知道我用過這個。但從我的回答判斷,你可以添加一個完成塊來刪除視圖。 – edc1591 2014-04-21 23:46:37
感謝您回覆我的評論。基於這個和其他一些問題,我能夠得到它的工作。 – user664939 2014-04-22 00:05:28