gpt4 book ai didi

ios - Xcode 6 - 在设备上运行应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 02:29:36 25 4
gpt4 key购买 nike

当我在模拟器上运行我的应用程序时,它工作正常。然而,当我在 iPhone 上运行它时,应用程序可以正常工作,但有时会暂停并崩溃?我该如何解决这个问题?我可以去哪里诊断问题?

我在主页的背景中添加了过渡图像。我使用了 Instruments,在 Allocations->Category 下,它使用了 PNG_Data 中的大量内存。我只是在我的 Xcode 项目中包含大约十二张 .png 照片。下面是使用图像的代码。

extension Array {
func shuffled() -> [T] {
var list = self
for i in 0..<(list.count - 1) {
let j = Int(arc4random_uniform(UInt32(list.count - i))) + i
swap(&list[i], &list[j])
}
return list
}
}

import Foundation

import UIKit

class ViewController: UIViewController {

@IBAction func unwindSegue(segue: UIStoryboardSegue) {

}
@IBOutlet weak var imageView: UIImageView!

// Array of images
let images = [
UIImage(named: "nature1@2x.png")!,
UIImage(named: "nature2@2x.png")!,
UIImage(named: "desk2@2x.png")!,
UIImage(named: "new_york8@2x.png")!,
UIImage(named: "new_york9@2x.png")!,
UIImage(named: "new_york10@2x.png")!,
UIImage(named: "new_york11@2x.png")!,
UIImage(named: "new_york14@2x.png")!,
UIImage(named: "new_york15@2x.png")!,
UIImage(named: "rainy_window1@2x.png")!,
UIImage(named: "rainy_window2@2x.png")!,
UIImage(named: "new_york16@2x.png")!,
UIImage(named: "new_york17@2x.png")!,
UIImage(named: "wall_st2@2x.png")!]

// Setting durations and intervals for transitions
var index = 0
let animationDuration: NSTimeInterval = 1.5
let switchingInterval: NSTimeInterval = 4


// VIEW DID LOAD
override func viewDidLoad() {
super.viewDidLoad()

imageView.image = images[index++]
animateImageView()


}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(2.5, animations: {()-> Void in
self.logo.alpha = 1.0})
}

// Function that animates the background
func animateImageView() {
CATransaction.begin()

CATransaction.setAnimationDuration(animationDuration) // passing in animationDuration
CATransaction.setCompletionBlock {
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(self.switchingInterval * NSTimeInterval(NSEC_PER_SEC)))
dispatch_after(delay, dispatch_get_main_queue()) {
self.animateImageView()
}
}

let transition = CATransition()
transition.type = kCATransitionFade // the type of transition

var new_images = images.shuffled() // SHUFFLING the images array

imageView.layer.addAnimation(transition, forKey: kCATransition)
imageView.image = new_images[index]

CATransaction.commit()

index = index < images.count - 1 ? index + 1 : 0
}

最佳答案

这是一件非常愚蠢的事情:

let images = [
UIImage(named: "nature1@2x.png")!,
UIImage(named: "nature2@2x.png")!,
UIImage(named: "desk2@2x.png")!,
UIImage(named: "new_york8@2x.png")!,
UIImage(named: "new_york9@2x.png")!,
UIImage(named: "new_york10@2x.png")!,
UIImage(named: "new_york11@2x.png")!,
UIImage(named: "new_york14@2x.png")!,
UIImage(named: "new_york15@2x.png")!,
UIImage(named: "rainy_window1@2x.png")!,
UIImage(named: "rainy_window2@2x.png")!,
UIImage(named: "new_york16@2x.png")!,
UIImage(named: "new_york17@2x.png")!,
UIImage(named: "wall_st2@2x.png")!]

基本上你是在说,“加载所有这些图像并同时保留它们。”图像巨大,所以内存自然会耗尽。

创建一个图像名称数组很好,因为名称只是很小的字符串;那么为什么不这样做呢?然后仅在您真正需要时才加载一个,以将其显示在界面中。

关于ios - Xcode 6 - 在设备上运行应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28131100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com