小编Ser*_*mer的帖子

使用 UIImage 时如何刷新缓存以释放内存 - Swift 3.0

在阅读了关于 SO 和其他文章(见下文)的许多答案后,当您将多个图像加载到动画数组中时,管理内存的最佳方法是什么?

http://www.alexcurylo.com/2009/01/13/imagenamed-is-evil/

以下是我的目标:

  1. 创建动画数组(见下面的代码)
  2. 动画播放后刷新缓存并加载另一个动画(冲洗,清洗,重复,你明白了:)

正如苹果所说 https://forums.developer.apple.com/thread/17888

使用UIImage(named: imageName)缓存图像,但在我的情况下,在连续播放 2-3 个动画后,iOS 终止应用程序(操作系统不响应内存不足警告而是终止应用程序 - 请参阅下面的代码结尾)

我不想缓存图像,而是我们可以:

  1. 每次动画完成时刷新内存,然后加载新动画;或者
  2. 当用户移动到新场景时刷新内存

这是我的代码:

// create the Animation Array for each animation

func createImageArray(total: Int, imagePrefix: String) -> [UIImage]{
    var imageArray: [UIImage] = []
    for imageCount in 0..<total {
        let imageName = "\(imagePrefix)-\(imageCount).png"
        let image = UIImage(named: imageName)! // here is where we need to address memory and not cache the images

        //let image = UIImage(contentsOfFile: imageName)! // maybe this?

        imageArray.append(image)
    } …
Run Code Online (Sandbox Code Playgroud)

uiimage ios swift

5
推荐指数
1
解决办法
1611
查看次数

如何阻止函数在 Swift 3.0 中运行

我有一个函数可以开始播放异步运行的动画(在后台)。使用完成处理程序无限期调用此动画(见下文)。有没有办法在按下另一个按钮时关闭此功能?

这是我的代码:

func showAnimation() {
    UIView.animate(withDuration: 1, animations: {
        animate1(imageView: self.Anime, images: self.animation1)
    }, completion: { (true) in
        DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
            self.showAnimation() // replay first showAnimation
        }
    }) 
 }
Run Code Online (Sandbox Code Playgroud)

然后按下另一个按钮,我们关闭上述功能

showAnimation().stop();
Run Code Online (Sandbox Code Playgroud)

谢谢

uiviewanimation ios swift

4
推荐指数
2
解决办法
5811
查看次数

脚本中的$ REMOTE_ADDR变量不起作用

我最近将PHP 4.0脚本转换为PHP 5.6,同时将我的服务器从4.0升级到5.6

但是,$REMOTE_ADDRPHP脚本中的行现在没有返回值,因为服务器正在运行PHP 5.6并且我无法解决这个问题:

$EmailFooter="REFERENCE COMPUTER ADDRESS: ($REMOTE_ADDR)";
Run Code Online (Sandbox Code Playgroud)

php php-5.6

1
推荐指数
1
解决办法
155
查看次数

如何向 DispatchQueue 添加时间延迟变量

首先我使用 arc4random 创建了一个 randomDelay 值

然后我想将 randomDelay 值添加到 DispatchQueue 以创建一个随机时间延迟变量

这是我的代码:

func animation1() {

UIView.animate(withDuration: 1, animations: {

    // various code

}, completion: { (true) in

    //delay calling the function by the randomDelay value of '0' to '2' seconds
    let randomDelay = arc4random_uniform(3)
    DispatchQueue.main.asyncAfter(deadline: .now() + randomDelay) { // the randomDelay value throws an unresolved identifier 'randomDelay' error
        self.showAnimation2() // Go to the next function
    }
  })
}
Run Code Online (Sandbox Code Playgroud)

谢谢

grand-central-dispatch ios swift

0
推荐指数
1
解决办法
776
查看次数