加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – UIView animateWithDuration:动画:完成:应用

发布时间:2020-12-16 06:59:24 所属栏目:百科 来源:网络整理
导读:试图从KVO观察中调用此消息.下载图像后,将发送此消息.完成块中的消息还包含一个正常工作的动画(动画正确).此动画应用没有动画发生的变换(等待动画的长度,然后跳转到最终状态). /** * Discover the subview with the supplied tag,attach the fullsize image
试图从KVO观察中调用此消息.下载图像后,将发送此消息.完成块中的消息还包含一个正常工作的动画(动画正确).此动画应用没有动画发生的变换(等待动画的长度,然后跳转到最终状态).

/**
 *  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];             
    }   

}

解决方法

线程睡眠的目的是什么?

如果你使主线程休眠,那么它不会在此期间更新动画.

如果你没有在主线程上调用它,那么它也不会起作用,因为UIKit动画不是线程安全的,只能从主线程中可靠地使用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读