2

I have 2 views. One is TableView with custom cells (image and label) and second is adding data. I implemented taking pictures/choosing one from a library. If the image is longer than wider TableView automatically rotates it by 90 degrees.

I never encountered with this issue, any ideas what's causing it?

This is how I save images:

func saveImageAndCreatePath(image: UIImage) -> String {
        let imgData = UIImagePNGRepresentation(image)
        let imgPath = "image\(NSDate.timeIntervalSinceReferenceDate()).png"
        let fullPath = documentsPathforFileName(imgPath)
        imgData?.writeToFile(fullPath, atomically: true)
        return imgPath
    }
Kira
  • 1,575
  • 4
  • 26
  • 48

1 Answers1

1

Download UIImage+fixOrientation.h and UIImage+fixOrientation.m files from here: https://www.dropbox.com/sh/gin2valk9pg4rmq/AABK7aN-ce3r9aTa4Z-e8nF3a?dl=0. Add those two files to your project and Xcode will ask if you want to make Bridging Header. Select Yes and in that bridging header add

#import "UIImage+fixOrientation.h"

Now you will be able to use that in your code like so:

fixedImage = image.fixOrientation()

Remember that you can use Objective-C files within Swift code: How to import Objective-C code into Swift from the same target

Sasha Kozachuk
  • 1,283
  • 3
  • 14
  • 21
  • @KiraArik you are welcome. Can you please also upvote my answer. I am new here and want to build reputation. Thanks in advanced. – Sasha Kozachuk Mar 11 '16 at 22:34
  • I don't have privileges to do so, I'm new also. I won't forget about your help, as soon as gain privileges I will upvote. – Kira Mar 11 '16 at 22:38