試圖從KVO觀察中調用此消息。一旦圖片下載完成,這條消息就會發送出去。完成塊中的消息還包含可正常工作的動畫(正確動畫)。該動畫應用不帶動畫的轉換(等待動畫的長度,然後跳轉到最終狀態)。UIView animateWithDuration:動畫:完成:應用轉換,而不是動畫
/**
* Discover the subview with the supplied tag, attach the fullsize image to the view
* scale to fullsize and begin retract.
* @param viewTag int - #FUTURE USE# - The tag of the view to be animated.
* @param image UIImage - #FUTURE USE# - The image to be applied to the view.
* @return void
*/
- (void)animateViewWithTag:(int)viewTag andImage:(UIImage *)image {
Panel *activePanel = [self.panels objectAtIndex:currentIndex];
UIView *activePanelView = [self.view viewWithTag:activePanel.panelId];
// Display the transition to the fullsize version of the panel image.
// Determine the scale that needs to be applied to the view to show
// the image in the appropriate scaling. If scaled image is greater than
// the size of the screen, find the best fit.
float scale = image.size.width/activePanelView.frame.size.width;
if (image.size.width > self.view.window.frame.size.width || image.size.height > self.view.window.frame.size.height) {
// The image will scale beyond the bounds of the window, scale must be adjusted.
scale = self.view.window.frame.size.width/activePanelView.frame.size.width;
}
CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);
[UIView animateWithDuration:1.0
animations:^{
// Get the fullsize image and display it in the growing panel.
[activePanelView setTransform:transform];
[NSThread sleepForTimeInterval:3.0];
}
completion:^(BOOL finished) {
[self retractImage:activePanelView];
}];
}
#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
int tmpInt = (int)context;
UIImage *tmpImage = [change objectForKey:NSKeyValueChangeNewKey];
if (keyPath == @"imgOriginal") {
[self animateViewWithTag:[(Panel *)object panelId] andImage:tmpImage];
}
}
你嘗試在主線程上調用這個方法嗎? – NeverBe 2012-03-19 19:55:04
我用[dispatch_get_main_queue(),^ {[animate ....)包裝了[self animateViewWithTag:]像這樣效果。 – Kyle 2012-03-19 20:13:05
我想知道,爲什麼你傳遞'required'' viewTag'而不是使用它:)希望能幫助到你。 – 2012-03-19 22:36:21