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


Post sketches, screenshots, videos (Quicktime Player), and links to your progress.

Ask questions and share resources that help you build your app.


Still stuck…probably about 10 hours on the pinch gesture with 0 success.
I tried using different solutions and same result.
I thought about using this, but it gives me an error about UIVIEW not having transform…

@IBAction func scaleImage(sender: UIPinchGestureRecognizer) {
  sender.view.transform = CGAffineTransformScale(sender.view.transform, sender.scale, sender.scale)
  sender.scale = 1


when you instantiate your UIImageView (one per photo) you create the gesture.
At the creation you give the action to execute when it is detected.
Here are my 2 functions to deal with pinch :

func createPinchGestureRecognizer(targetView:UIImageView) {
    let pinch = UIPinchGestureRecognizer(target: self, action: "handlePinch:")

func handlePinch(nizer:UIPinchGestureRecognizer) {
    nizer.view!.transform = CGAffineTransformScale(nizer.view!.transform,
        nizer.scale, nizer.scale)
    nizer.scale = 1

With those 2 when i create my photo UIImageView i assign the gesture with :



I had not the time to deal with textLabel on photos this week end. So here is my project, with only the photo part :smile:

the code


Try this - sender.view?.transform = CGAffineTransformScale(sender.view!.transform, sender.scale, sender.scale)


Unbelievable…I think all the methods I have tried actually did work…I just didn’t know how to rotate and pinch on the Simulator…best 10hrs of my life :smiley: So apparently you have to press Opt key, then click with both fingers and then rotate pinch…yarrr


Ok, I am really surprised I’ll be the first to post something :slight_smile: I thought I was pretty behind on everything…
Anyway, the app is somewhat finished, some things are buggy, but that’s it so far.
That’s so far the longest app I’ve written :smile:

If you have solutions on the following problems, let me know:

  • when the main view is loaded it repeats the audio play, but not the
    animated labels, even though they are called in the ViewDidLoad (
    both audio and anim are called at the same times )
  • when you load the images from the Source, even though your screen is
    in landscape the browsing is in portrait. I mean, I guess I can
    make a function that detects the screen orientation and then
    forces it in a certain way, but really ?! There has to be an
    easier way for that…
  • also wasn’t sure how to just scale the newly created UIImageView, based on either of it’s sizes not Bigger than let’s say 100px, but I just made em square for now…
  • I am sure there was more stuff, but I can’t remember now…

Also…didn’t want to waste too much time on design, so it’s all black :smiley: :smiley:


Repo(full code and files ):


This is awesome! I like the way you handled the “z-order” of photos / text (those “Front” / “Back” buttons), like they were layers. Good stuff.


I like it too, but to be honest at the beginning I wanted to do it with the bringToFront(subView) method, but couldn’t make it. I don’t know why as all UIImageViews are parented by the same Image View…but w/e :smile:


Btw, for that method was a really pain the butt to make the button check if the View is a Label or Image first and then check which one is it…

I wonder if there was a way to make it so the function works regardless if the item is Label or Image.
It would’ve shaved at least 70-0 lines of code here :smiley:


Anyone find out how to lock the orientation of the Image Picker? If my device is landscape i just want it to appear landscape, is that possible?


Here is my app in progress.

When I drag a letter from the bottom, it doesn’t move initially, then it does
UIPicker Orientation is in portrait
Can I set the max scale size of images?
When I rotate an image, the shadow doesn’t move with it

Code: https://www.dropbox.com/s/bb8rfb3y6x1vfvu/AlphaFridgeViewController.swift?dl=0


@rajeejones Does this help?


@PaulSolt thats in Objective-C

I tried converting it to the best i could, but its not working


Good point, I’ll make a note and film a video on this tomorrow.

I’m working to address a lot of the common questions.


Just briefly looked at your code. Good job.
Btw, you might wanna try adding and playing with labels too as I think that was very beneficial to me. Using only one type ( in your case UIImageView is much more easier ).

If you wanna see a shadow on your rotate you have to add it to the correct handle.
You have only added it to the pan ( move ) gesture.
You just have to repeat the same structure:

if rotateGesture.state == UIGestureRecognizerState.Began{           

        if rotateGesture.state == UIGestureRecognizerState.Ended {

then you just gotta replace the (itemMoved) with the correct sender from your rotate gesture.


Btw, I started my own blog to record important stuff. I made it mostly to ease myself in learning and so I have a clear reference library to go back to if I forget something, but feel free to look it up.
This is my rotate gesture:


Amazing app @ravenshore!
I tried to put the labels and images into an UIImageView, but then I could not use the gestures after I added the items to the imageView subview.

How can you still use gestures on single items in a whole UIImageView?


The way I did is I assign the gestures as I create each Label/ Image.
If you look at my code ( sorry my code is really messy :slight_smile: ) you can see it :

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
 var x = CGFloat(arc4random_uniform(100)+50)
 var y = CGFloat(arc4random_uniform(100)+50)
 var image = info[UIImagePickerControllerOriginalImage] as UIImage
 var imageViewNew = UIImageView(frame: CGRectMake(100, 100, 150 , 150))
                    imageViewNew.center = CGPoint(x: x, y: y)
                    imageViewNew.image = image

                    imageViewNew.multipleTouchEnabled = true
                    imageViewNew.userInteractionEnabled = true


                    dismissViewControllerAnimated(true, completion: nil)



If you add them as a subview, you’ll need to make sure the parent view (i.e. UIImageView) is set to userInteractive.

var imageView = UIImageView()
// ...
imageView.userInteractionEnabled = true
// ... addSubviews

To get around that issue, you can just add to the view, rather than the UIImageView, but you’d need to rearrange the order so that the “subviews” aren’t behind the ImageView.

Use the view hierarchy management APIs in UIView


Which one do you think is better ?
I am using the first option, but it made things a bit more complicated as instead of Parent now I have Parent and Grandparent :smile: