简体   繁体   English

UIImage在模拟器上运行但在设备swift上崩溃

[英]UIImage works on simulator but crashes on device swift

I have checked UIImage works on the simulator but not working on the device. 我已经检查过UIImage在模拟器上工作但没有在设备上工作。 Here's the code: 这是代码:

imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
let image = UIImage(named: "sample.png")
imageView.image = image
view.addsubview(imageView)

How can I solve this problem? 我怎么解决这个问题?

Extremely larger images bigger than UIImageView size causes the crash. 比UIImageView大小更大的图像会导致崩溃。 UIImageView size is 50 x 50, but the image size is 900 x 900. This works on simulator but doesn't work on iOS device. UIImageView尺寸为50 x 50,但图像尺寸为900 x 900.这适用于模拟器,但不适用于iOS设备。

You need to add your image to 'Copy Bundle Resources'. 您需要将图像添加到“复制捆绑资源”。

Select Target -> Build Phases -> Copy Bundle Resources and add your image to the list. 选择Target - > Build Phases - > Copy Bundle Resources并将图像添加到列表中。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 应用程序在真实设备上崩溃,但在模拟器上运行 - Swift app crashes on real device but works on simulator NumberFormatter 适用于模拟器,但不适用于设备 swift - NumberFormatter works on simulator but not on device swift Simulator上的Xcode应用程序可以在真实设备崩溃时正常工作 - Xcode app on Simulator works, on real device crashes AVAudioFile初始化可在模拟器上运行,但在设备上崩溃 - AVAudioFile init works on simulator but crashes on device 应用程序在设备上崩溃 - 在Simulator上完美运行 - Application crashes on device - works perfectly on Simulator 应用程式在装置上当机,但在Simulator上运作正常 - App crashes on device, however works fine on Simulator UILabel在运行时为nil,可在模拟器上运行,但在设备上崩溃 - UILabel is nil on runtime, works on simulator, but crashes on device 应用程序在模拟器上正常运行,但在设备上崩溃 - Application works fine on the simulator but crashes on the device Spritekit 应用程序在设备上运行时崩溃,在 swift 3 转换后可在模拟器上运行 - Spritekit app crashes when run on device, works on simulator after swift 3 conversion iOS Webkit不在设备上工作,但在swift的模拟器上运行 - iOS Webkit not working on device, but works on simulator at swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM