2016-06-10 2 views
0

열의 마지막 행을 탭할 때마다, 아이폰에서는 앱이 충돌하지만 시뮬레이터에서는 충돌하지 않는다. 다른 모든 것은 잘 작동합니다. 오류 메시지가 표시되지 않습니다. 코드는 시뮬레이터와 함께 완벽하게 작동합니다.아이폰에서 앱이 다운되지 않는다. 시뮬레이터에 없다.

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. 
    } 
    */ 

} 
+4

문제를 더 잘 이해하기 위해 표시되는 몇 가지 코드 또는 오류 메시지를 함께 적어주십시오. – Nirupa

+0

내 질문에 답해 주셔서 감사합니다. 이제 위의 코드를 게시했습니다. – Ram

+2

예외 중단 점을 추가하면 충돌하는 코드 줄을 확인할 수 있습니다. –

답변

0

로드하는 모든 이미지가 휴대 전화 메모리가 부족합니다. 최근에이 문제가 발생했습니다. 오류는 없지만 때로는 디버그 콘솔에서 "메모리 부족 경고"를 보았습니다.

진단하려면 이미지 이름의 배열을 만들고 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 % (바이트로)가되어로드가 훨씬 빨라졌습니다. 동료들에게 원본 이미지와 크기 조정/손실 이미지를 보여 주었지만, 차이점을 볼 수 없었습니다 (어떤 것은 그것이 농담이라고 생각했습니다).

+0

많은 조언을 주셔서 감사합니다! 많이 감사 :-) – Ram

0

많은 수의 이미지 (100 개)로 만든 App과 비슷한 문제가있었습니다. 이들의 존재도 앱을 다소 느리게 만들었습니다. 이미지 품질에 영향을주지 않고 각 이미지의 파일 크기를으로 줄였습니다. 그것은 일했다!! Apple의 '미리보기'에서 쉽게 완성되었습니다.

해결 방법 : '미리보기'

  • 고토 메뉴 상단에 맥 OSX에서

    1. 열기 이미지 ... '도구'... '크기 조정'

    2. 이미지의 픽셀 크기 줄이기 + 저장

    3. 새로 저장 한 이미지를 Xcode 귀하의 애플 리케이션을위한

    응용 프로그램에서 이미지 품질의 감소를 보지 않고 파일 크기를 40 % 줄입니다!

  • +0

    그것은 작동합니다! 정말 고맙습니다! – Ram