Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Genady Novak
Genady Novak
5,164 Points

UIImagePickerController

I'm trying to present UIimageController with animation. The default animation present the UIimageController from bottom to top. How to present UIimageController from top to bottom

(I'm using swift)

Thanks!!

4 Answers

Noah Hanover
Noah Hanover
13,272 Points

Use the self.dismissViewController function. It took me FOREVER to find this out. I hope it works!

Genady Novak
Genady Novak
5,164 Points

I have UItabBarViewController with bar button that should activate the camera (the same as Instagram). if I will dismiss the view controller it will not present me the camera

Noah Hanover
Noah Hanover
13,272 Points

I'm not sure that I follow what you are saying. Can you post some of the code up, so that I can take a look?

Genady Novak
Genady Novak
5,164 Points

The following UIViewController Class is one to the views that loads from my UITabBarController

import Foundation import MobileCoreServices

class CameraView: UIViewController , UINavigationControllerDelegate, UIImagePickerControllerDelegate { var image : UIImage! var imagePicker : UIImagePickerController!

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.showCamera()

}


func showCamera(){
    if self.image == nil{

        self.imagePicker = UIImagePickerController()
        self.imagePicker?.delegate = self
        self.imagePicker?.allowsEditing = false
        if (UIImagePickerController.isSourceTypeAvailable(.Camera)){
            self.imagePicker?.sourceType = .Camera
        }
        self.imagePicker?.mediaTypes = [kUTTypeImage!]
        self.presentViewController(self.imagePicker!, animated: false, completion: nil)
    }
}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    self.tabBarController?.selectedIndex = 0
    self.dismissViewControllerAnimated(false, completion: nil)
}

}

Noah Hanover
Noah Hanover
13,272 Points

I understand, you are trying to Present the ViewContoller, but with the same animation as dismissViewControllerAnimated has. I'm sorry, but I'm not sure how to do this. If you look at maybe some stackOverFlow questions, you may be able to find out. If not, try finding a different way to present a view controller

Genady Novak
Genady Novak
5,164 Points

Ok thanks for the help