ImageChange using button pressed in iPhone


In this example we will see how to ImageChange using button pressed. So let see how it will work in our application. My previous post you can find out from here KeyBoard example
Step 1: Open the Xcode, Create a new project using View Base application. Give the application “ImageChange”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: Open the ImageChangeViewController.h file and make the following changes in the file:
#import <UIKit/UIKit.h>
@interface ImageChangeViewController : UIViewController {
UIView *View3;
UIImageView *View1;
UIImageView *View2;
}
@property (nonatomic, retain) UIView *View3;
@property (nonatomic, retain) UIImageView *View1;
@property (nonatomic, retain) UIImageView *View2;
- (IBAction)MoveImage:(id)sender;
@end
Step 4: Double click the ImageChangeViewController.xib file and open it to the Interface Builder. First drag the UIButton from library and place it to the view window. Select the Button and bring up Connection Inspector and drag Touch Up Inside to the File’s Owner icon and select MoveImage: action. Now save the .xib file and go back to the Xcode.
Step 5: In the ImageChangeViewController.m file make the following changes:
#import "ImageChangeViewController.h"
#define kHeight         320.0
#define kWidth                  400.0
#define kTransitionDuration     0.75
#define kTopPlacement           80.0
@implementation ImageChangeViewController
@synthesize View3, View1, View2;
- (void)dealloc
{
[View1 release];
[View2 release];
[View3 release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark – View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"TransitionsTitle"@"");
CGRect frame = CGRectMake(round((self.view.bounds.size.width - kWidth)/ 2.0),
kTopPlacement, kWidth, kHeight);
self.View3 = [[[UIView alloc] initWithFrame:frame] autorelease];
[self.view addSubview:self.View3];
frame = CGRectMake(0.0, 0.0, kWidth, kHeight);
self.View1 = [[[UIImageView alloc] initWithFrame:frame] autorelease];
self.View1.image = [UIImage imageNamed:@"1.png"];
[self.View3 addSubview:self.View1];
CGRect imageFrame = CGRectMake(0.0, 0.0, kWidth, kHeight);
self.View2 = [[[UIImageView alloc] initWithFrame:imageFrame]autorelease];
self.View2.image = [UIImage imageNamed:@"2.png"];
}
- (IBAction)MoveImage:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:kTransitionDuration];
[UIView setAnimationTransition:([self.View1 superview] ?
UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)
forView:self.View3 cache:YES];
if ([self.View2 superview])
{
[self.View2 removeFromSuperview];
[self.View3 addSubview:self.View1];
}
else
{
[self.View1 removeFromSuperview];
[self.View3 addSubview:self.View2];
}
[UIView commitAnimations];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.View3 = nil;
self.View2 = nil;
self.View1 = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Step 6: Now compile and run the application in the Simulator.
You can Download SourceCode from here ImageChange

Related Posts:

  • Comparing iPhone calendar apps at a glanceI've compared the main screens of iPhone Twitter apps, weather apps, and podcast apps, and next on the agenda is calendar apps. While iOS contains a default calendar app, and many people find it affable enough,… Read More
  • Top 10 iPhone Apps For Dating in 2013Get ready to make your dates more beautiful and memorable through your iPhone, because here we bring you a brand new list of top 10 iPhone apps for dating in 2013 which will surely help you in making your day adorable and unf… Read More
  • Apple Officially Announces iBookstore for JapanFollowing the release of iBooks 3.1, Apple has officially announced the availability of the iBookstore in Japan.You can find the full press release below. Notably, the iBookstore is now in 51 countries, free books are av… Read More
  • Fantastical for iPhone gets even smarter and fasterFantastical, the fantastically functional calendar app by Flexibits, has just been updated to version 1.1. I've been beta testing it for a while, and as clichéd as it sounds, it really does make the already great app eve… Read More
  • Things for iPhone, iPad, and Mac reviewThings is a detailed task manager by Cultured Code that will help you organize your very busy life. Things isn't just a simple to-do list, it's a serious "get things done" (GTD) tool that allows you to create projec… Read More

0 comments:

Post a Comment