iPhone上的应用程序崩溃不在模拟器上
每当我点击列中的最后一行,应用程序就会在iPhone上崩溃,但不会在模拟器上崩溃。其他一切正常。我没有收到任何错误消息。代码与模拟器一起工作得很好。iPhone上的应用程序崩溃不在模拟器上
import UIKit
class EarthVC: UIViewController {
@IBOutlet var slideShow1: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
slideShow1.animationImages = [
UIImage(named: "Earth1.jpg")!,
UIImage(named: "Earth2.jpg")!,
UIImage(named: "Earth3.jpg")!,
UIImage(named: "Earth4.jpg")!,
UIImage(named: "Earth5.jpg")!,
UIImage(named: "Earth6.jpg")!,
UIImage(named: "Earth7.jpg")!,
UIImage(named: "Earth8.jpg")!,
UIImage(named: "Earth9.jpg")!,
UIImage(named: "Earth10.jpg")!,
UIImage(named: "Earth11.jpg")!,
UIImage(named: "Earth12.jpg")!,
UIImage(named: "Earth13.jpg")!,
UIImage(named: "Earth14.jpg")!,
UIImage(named: "Earth15.jpg")!,
UIImage(named: "Earth16.jpg")!,
UIImage(named: "Earth17.jpg")!,
UIImage(named: "Earth18.jpg")!,
UIImage(named: "Earth19.jpg")!,
UIImage(named: "Earth20.jpg")!,
UIImage(named: "Earth21.jpg")!,
UIImage(named: "Earth22.jpg")!,
UIImage(named: "Earth23.jpg")!,
UIImage(named: "Earth24.jpg")!,
UIImage(named: "Earth25.jpg")!,
UIImage(named: "Earth26.jpg")!,
UIImage(named: "Earth27.jpg")!,
UIImage(named: "Earth28.jpg")!,
UIImage(named: "Earth29.jpg")!,
UIImage(named: "Earth30.jpg")!,
UIImage(named: "Earth31.jpg")!
]
slideShow1.animationDuration = 93
slideShow1.startAnimating()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
随着您加载的所有图像,很可能是您的手机内存不足 - 我最近遇到了这个问题。没有错误,但有时我在调试控制台上看到“低内存警告”。
为了诊断它,创建一个图像名称的数组,循环遍历该数组以填充UIImage的数组,但检查它们是否按照原样加载。然后,您可以将其设置为animationImages。所以,
let imageNames = [
"Earth1.jpg",
"Earth2.jpg",
// ...
"Earth31.jpg"
]
var images = [UIImage]()
for name in imageNames
{
guard let image = UIImage(named: name) else {
NSLog("Failed to load image \(name)")
continue
}
images.append(image)
}
slideShow1.animationImages = images
你可以在继续设置一个断点,看看你有多远。
假设是这样,修复问题,您将需要使用图像编辑程序使图像更小(以像素为单位)。就我而言,我的图像是以4000x6000像素拍摄的照片;我发现将它们调整为实际显示的大小会产生变化。另外,保存50%文件损失的文件大约占原始文件大小的15%(以字节计),这使得它们的加载速度更快。我向同事展示了原始的和调整大小的/有损图像,他们看不出有什么区别(有人认为这是一种笑话)。
非常感谢您的建议!非常感谢:-) – Ram
我有一个类似的问题,我用大量的图像(100)制作的应用程序。他们的存在也使应用程序有所放慢。当我减少了每个图像的文件大小 - 而不会影响图像质量。有效!!在Apple的“预览”中轻松完成。
解决方案:
公开赛在Mac OSX上的图像与 '预览'
转到菜单顶部... '工具' ... '调整大小'
减少图像的像素大小+保存
将新保存的图像放回Xcode为您的应用程序
减少文件大小的40%,没有看到应用程序的图像质量下降任何工作!
它的工作原理!非常感谢! – Ram
请包括您看到的一些代码或错误消息,以便更好地理解您的问题。 – Nirupa
谢谢你回答我的问题。现在我已经发布了上面的代码。 – Ram
尝试添加异常断点,以便您可以检查哪一行代码会导致崩溃 –