PDA

View Full Version : Background Pic, Rotate, and Swap Image




Josh Kahane
Apr 28, 2009, 09:04 AM
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. :)



iphonedevelop18
Apr 28, 2009, 02:41 PM
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
IBOutlet UIImageView *myImage;
Now go into your .m file and look for the should autorotate method, you should see a return (interfaceOrientation == UIInterfaceOrientationPortrait);
change that to return YES;
now build and go and it should show your image and rotate when you turn the simulator.
Hope this helps!

Josh Kahane
Apr 28, 2009, 04:11 PM
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?

iphonedevelop18
Apr 28, 2009, 08:27 PM
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?

Create a method in xcode (.h view controller file) for the button you'll add later, like so.
- (IBAction)bgClick:(id)sender;
also add it into your .m file
- (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/ (http://icodeblog.com/)

Josh Kahane
Apr 29, 2009, 02:28 AM
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.