我有一个将视频用作AVURLAsset并按时间间隔剪切视频的功能。我也有UIImageview IBOutlet叫做previewImageView,我想在执行函数时更改图像。在viewDidLoad中调用此函数。在函数执行完毕后,似乎只设置了previewImageView。我的代码在下面
NameError: name 'utf8' is not defined
中的建议进行操作
答案 0 :(得分:0)
您需要使图像无效才能立即刷新。
只需调用UIView的setNeedsDisplay()
函数。
dispatch_async(dispatch_get_main_queue())
{
self.previewImageView.image = image
self.previewImageView.setNeedsDisplay()
}
答案 1 :(得分:0)
改为使用// call this method when you want to start updates
- (void)startUpdates
{
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doFrame)];
_displayLink.frameInterval = 1;
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
// I'll let you guess
- (void)stopUpdates
{
[_displayLink invalidate];
_displayLink = nil;
}
// In this method, do any needed updates.
// Note that it will not necessarily be called every single frame,
// so check actual time to decide what to display
- (void)doFrame
{
}
,它会尝试与屏幕刷新同步。
这是一些Objective-C代码,我将把它作为练习让读者将其转换为Swift。
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<h3>With Reordering</h3>
<div class="row">
<div class="col-sm-4">
<div class="alert alert-warning">UPPER 1
</div>
</div>
<div class="col-sm-8">
<div class="alert alert-danger">LOWER 1
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4 col-sm-push-8">
<div class="alert alert-info">LOWER 2
</div>
</div>
<div class="col-sm-8 col-sm-pull-4">
<div class="alert alert-danger">UPPER 2
</div>
</div>
</div>
</div>
<hr>
<div class="container">
<h3>
Without Reordering
</h3>
<div class="row">
<div class="col-sm-4">
<div class="alert alert-warning">UPPER 1
</div>
</div>
<div class="col-sm-8">
<div class="alert alert-danger">LOWER 1
</div>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<div class="alert alert-danger">UPPER 2
</div>
</div>
<div class="col-sm-4">
<div class="alert alert-info">LOWER 2
</div>
</div>
</div>
</div>
答案 2 :(得分:0)
我通过在viewDidLoad中的后台线程中调用我的getImageAtInterval方法并调用&#34; previewImageView.image = image&#34;来解决了这个问题。在UIThread:)