[Swift 1] 2nd App Challenge - Photo Collage or Picture Caption App


#21

Actually… after filming the code to snapshot the view hierarchy, it does make sense to want to add content as a subview to an UIImageView.

I’ll be posting videos for 11.6 and 11.7 to cover taking a screenshot of the views, and why you might want to add views to the UIImageView.

11.6 Tutorial - Take a screenshot of the iPhone screen - http://learn.iphonedev.tv/lecture/103427/116-tutorial-take-a-screenshot-of-the-iphone-screen

11.7 Tutorial - Take a screenshot of non-UI content - http://learn.iphonedev.tv/lecture/103428/117-tutorial-take-a-screenshot-of-non-ui-content


#22

Thank you guys very much! @PaulSolt @ravenshore


#23

Hi Paul

Here is the code: https://gist.github.com/ariasfigueroa/4b9a7d2fbf07e6141a07


#24

Here is the second draft of the app. Removed the sluggish navigation with this, hope you like it :smile:



#25

Awesome work, this looks great.

Did you try to submit it to the App Store?


#26

Thanks. No, I haven’t, I think it’s far from worthy for the AppStore :slight_smile: I was thinking maybe I should still do it, just so I can get a better understanding of the process though…


#27

Yes, just do it. It’s a learning process and you need to start somewhere. It’ll be something you can show off.

I’d probably spend at most 1 week working on fixing anything and then I would submit. The sooner you ship something the better.


#28

Hi here is my app. I am going to carry on working on it to submit it. I thought I would put it up at this stage. It still has some things I have to fix. The reset button doesn’t reset the current angle or scale of the text when you add new ones after reseting. Thats the main large one. I had the help of Ravenshore so big thanks to you Sir!!

Things that work
Input image from camera or gallery and manipulate with gesture. You can add multiple images and do that.
Input text and label is editable with varying text changing functions. I will add more functions in the release.
Saving and sharing work well.
Oh love woking on Github as you can have different forks etc.

Problems:
Keyboard rising obscures what you are typing but its hard as have to have two different functions or something for the two labels. Might put the text entry on the picture and hide it after the return key has been pressed.
Reset doesn’t reset the angle of the label or picture so have to add that to the reset function.
Couldn’t get the status bar to stay white. No matter what I did.

Want to change the input for the font to a picker view ( have made it work with a special one from Github but can’t get more than one row to work)
The design will be different inside the app.
Want to add text alignment option, different text size option for different labels, google analytics and crashylitlcs.

Excuse the bad spelling I was doing that at 2.30am.

Gist link





#29

Hey guys,

I have implemented the “handlePanGesture” but needed to break it out in two different functions since I need to declare the type of the panGesture.view as either UILabel or UIImageView:

func handlePanGesture(panGesture: UIPanGestureRecognizer!) {
    // Get translation
    var translation = panGesture.translationInView(view)
    panGesture.setTranslation(CGPointZero, inView: view)
    panGesture.delegate = self
    
    // Add dx,dy to current image position
    var image = panGesture.view as! UIImageView
    image.center = CGPoint(x: image.center.x + translation.x, y: image.center.y + translation.y)
    
}

func handlePanGestureText(panGesture: UIPanGestureRecognizer!) {
    var translation = panGesture.translationInView(view)
    panGesture.setTranslation(CGPointZero, inView: view)
    panGesture.delegate = self
    
    var label = panGesture.view as! UILabel
    label.center = CGPoint(x: label.center.x + translation.x, y: label.center.y + translation.y)
}

Is it possible to factorize this code and put it all in one function (e.g. by recognizing the sender type?)

Best,

Max


#30
  1. Yes it is possible to write more “generic code”, however separating the two is totally fine.

You can keep it simple for now. It’s ok to write more code than you need when you’re learning.

  1. If you want to reuse logic, then instead of casting both to their specific types, convert it to UIView (parent class) that has the center attribute.

     func handlePanGesture(panGesture: UIPanGestureRecognizer!) {
         // Get translation
         var translation = panGesture.translationInView(view)
         panGesture.setTranslation(CGPointZero, inView: view)
         panGesture.delegate = self
         
         // Add dx,dy to current image position
         
         // Paul: Use as? and the if/let syntax for type safety
         if let gestureView = panGesture.view as? UIView {
             gestureView.center = CGPoint(x: image.center.x + translation.x, y: image.center.y + translation.y)
         }
     }