These are chat archives for devslopes/swiftios9

5th
Nov 2015
Mark Price
@spentak
Nov 05 2015 02:20
New video uploaded to Hot Topics Section of the course: Swift & Objective-C in the same project
itsalexbrown
@itsalexbrown
Nov 05 2015 02:21
Nice!
Evan Leong
@evanmayo
Nov 05 2015 08:24
hey @spentak ! I'm playing around with the showcase app, and I want to have the launch of the app go straight to the FeedVC if the user is already logged in to Facebook. It currently does it right now, but you can see the login window for a split second. Any hints on how to do this without briefly showing the log in window? Thanks!
Mark Price
@spentak
Nov 05 2015 15:02
Check if logged in on app delegate. If so make the feedvc the root view controller otherwise make login the root view controller. Will require some code
alexbuessing
@alexbuessing
Nov 05 2015 16:30
Hey @spentak for the favorite-places app, is it possible to put in more code than can fit the screen and be able to scroll down to access the additional text? Thanks!
alexbuessing
@alexbuessing
Nov 05 2015 16:54
And by more code I mean more text.
Jack Davis
@jackd942
Nov 05 2015 16:55
You could use a UIScrollView @alexbuessing, but that hasn’t been covered at that point in the course. If it bugs you, you can google it and get one going without too much trouble.
alexbuessing
@alexbuessing
Nov 05 2015 16:57
Thanks @jackd942.
Jack Davis
@jackd942
Nov 05 2015 16:58
He covers UIScrollView starting at lesson 73. You could move ahead and come back to it it you want also...
Larry Nguyen
@whatonearth
Nov 05 2015 19:29
could anyone tell me how to shhow the app contents in the search on iphone
Evan Leong
@evanmayo
Nov 05 2015 20:22
perfect, thanks @spentak !
Mark Price
@spentak
Nov 05 2015 20:52
@alexbuessing sorry for the delay. What @jackd942 use a scrollview.
Jack Davis
@jackd942
Nov 05 2015 22:21

If anybody else is interested in animating the frame up when the keyboard appears (as in the My Hood app), here is a bit of code to handle that. It also animates back down when dismissed as well as dismissing the keyboard if return is pressed or the view is tapped anywhere else.

Add the UITextFieldDelegate protocol to your vc and set your text field objects .delegate property to self:

class AddPostVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {


    @IBOutlet weak var titleField: UITextField!
    @IBOutlet weak var descriptionField: UITextField!
    @IBOutlet weak var postImg: UIImageView!

    var imagePicker: UIImagePickerController!

    override func viewDidLoad() {
        super.viewDidLoad()

        titleField.delegate = self
        descriptionField.delegate = self

        postImg.layer.cornerRadius = postImg.frame.width / 2
        postImg.clipsToBounds = true

        imagePicker = UIImagePickerController()
        imagePicker.delegate = self

    }

Then add these functions…

    func textFieldShouldReturn(textField: UITextField) -> Bool {
        titleField.resignFirstResponder()
        descriptionField.resignFirstResponder()
        return true;
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        titleField.resignFirstResponder()
        descriptionField.resignFirstResponder()
        self.view.endEditing(true)
    }

    func textFieldDidBeginEditing(textField: UITextField) {
        animateViewMoving(true, moveValue: 225)
    }

    func textFieldDidEndEditing(textField: UITextField) {
        animateViewMoving(false, moveValue: 225)
    }

    func animateViewMoving(up: Bool, moveValue: CGFloat) {
        let movementDuration: NSTimeInterval = 0.3
        let movement: CGFloat = ( up ? -moveValue : moveValue )
        UIView.beginAnimations("animateView", context: nil)
        UIView.setAnimationBeginsFromCurrentState(true)
        UIView.setAnimationDuration(movementDuration)
        self.view.frame = CGRectOffset(self.view.frame, 0, movement)
        UIView.commitAnimations()
    }