Background Pic, Rotate, and Swap Image

Discussion in 'iPhone/iPad Programming' started by Josh Kahane, Apr 28, 2009.

  1. macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #1
    Hi

    So I have started making my first iPhone app! Its very, very simple, but I wan to slowly expand it. I need some help with a few things. Its really simple stuff, but I would really appreciate any help, thank you.

    1. Firstly how can I set a background image? This is the first thing you see when you open the app.

    2. I want this image to be able to rotate when I turn my device.

    3. When I touch the screen I want the image to swap to my other chosen image.

    Would appreciate the help, so far only have set the name and icon of my app. :)
     
  2. macrumors member

    Joined:
    Feb 26, 2009
    #2
    go into Interface builder, go into the library drag a UIImageView into your view. Go into the inspector, and then go to the tab with a ruler on it, see the picture next to the width and height click the two inside arrows so there highlighted,then unclick all of the outside I type lines, except the top one, so there not highlighted.go into the first tab on that screen change the image to whatever image you want to show first. Now quit IB. Go into xcode, under your .h view controller file create an IBOutlet for the image view like so
    Code:
     IBOutlet UIImageView *myImage;
    Now go into your .m file and look for the should autorotate method, you should see a
    Code:
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    change that to
    Code:
     return YES;
    now build and go and it should show your image and rotate when you turn the simulator.
    Hope this helps!
     
  3. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #3
    This worked perfectly thanks, I now have my image on the screen and it rotates perfectly.

    Next thing. How can I get it so that when my Finger is on the screen it swaps the image?
     
  4. macrumors member

    Joined:
    Feb 26, 2009
    #4
    Create a method in xcode (.h view controller file) for the button you'll add later, like so.
    Code:
     - (IBAction)bgClick:(id)sender;
    also add it into your .m file
    Code:
     - (IBAction)bgClick:(id)sender {
            myImage.image = [UIImage imagenamed:@"MyOtherImage.png"];
    }
    Go into interface builder and add a UIButton to fill the whole screen go to the first tab and make it a custom button. Go into the files owner and connections tab in that and connect your method to the button. After doing that it should all work.

    I strongly recommend you either get a book or watch some tutorials from these sites, as this is very basic stuff.

    http://www.iphonedevcentral.org/viewtutorials.php?page=Tutorials&cmd=ViewAll&number=1

    http://icodeblog.com/
     
  5. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #5
    Ok thats fair enough I was struggling with getting through books etc so I though I'd try and throw myself in but clearly I am getting to much help with the simplest things, but I appreciate your help so far your code has been working well, except for one thing.

    I did what you said but firstly I have entered the code, and tried to connect that thing to the button in IB but I cant connect anything to the button. Secondly, I thought I'd see whats wrong by Building and going and its revealed errors, a couple I fixed but there are too I cant see whats wrong.

    Well Im going to try and run through your instructions again, if that doesn't work I'll give it a break and try learn it the proper way. :) Thanks.
     

Share This Page