This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Using custom view as a tab bar, it is declared in delegate so that it ca be available on all views. But the issue is the pushViewController is not implementing there. I am using the custom view to get the navigation controller animation on bottom bar because this can not be implemented on tab bar. So, how can i perform pushViewController to the bar buttons.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.homeViewController = [[[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil] autorelease];
navController = [[UINavigationController alloc]initWithRootViewController:self.homeViewController];
navController.navigationBar.barStyle = UIBarStyleBlack;
[self.window addSubview:self.navController.view];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate addCustomBottomBar];
[self.window makeKeyAndVisible];
return YES;
}
-(void)addCustomBottomBar{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
viewBotBar = [[UIView alloc]initWithFrame:CGRectMake(0, 402, 320, 79)];
viewBotBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"1aa.png"]];
[self.window addSubview:viewBotBar];
[self.window bringSubviewToFront:viewBotBar];
[UIView commitAnimations];
UIButton *btnHome = [UIButton buttonWithType:UIButtonTypeCustom];
btnHome.frame = CGRectMake(0, 25, 54, 50);
[btnHome setImage:[UIImage imageNamed:#""] forState:UIControlStateNormal];
[btnHome addTarget:self action:#selector(home) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnHome];
UIButton *btnLoc = [UIButton buttonWithType:UIButtonTypeCustom];
btnLoc.frame = CGRectMake(58, 25, 63, 50);
[btnLoc setImage:[UIImage imageNamed:#""] forState:UIControlStateNormal];
[btnLoc addTarget:self action:#selector(loc) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnLoc];
UIButton *btnSer = [UIButton buttonWithType:UIButtonTypeCustom];
btnSer.frame = CGRectMake(124, 25, 63, 50);
[btnSer setImage:[UIImage imageNamed:#""] forState:UIControlStateNormal];
[btnSer addTarget:self action:#selector(ser) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnSer];
UIButton *btnBook = [UIButton buttonWithType:UIButtonTypeCustom];
btnBook.frame = CGRectMake(190, 25, 63, 50);
[btnBook setImage:[UIImage imageNamed:#""] forState:UIControlStateNormal];
[btnBook addTarget:self action:#selector(book) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnBook];
UIButton *btnMore = [UIButton buttonWithType:UIButtonTypeCustom];
btnMore.frame = CGRectMake(256, 25, 62, 50);
[btnMore setImage:[UIImage imageNamed:#""] forState:UIControlStateNormal];
[btnMore addTarget:self action:#selector(more) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnMore];
btnDwn = [UIButton buttonWithType:UIButtonTypeCustom];
btnDwn.frame = CGRectMake(135, 0, 45, 28);
[btnDwn setImage:[UIImage imageNamed:#""] forState:UIControlStateNormal];
[btnDwn addTarget:self action:#selector(down) forControlEvents:UIControlEventTouchUpInside];
btnDwn.tag = 1;
[viewBotBar addSubview:btnDwn];
}
-(void)down
{
if (btnDwn.tag == 1) {
// perform your required functionality
btnDwn.tag = 2;
CGRect newFrameSize = CGRectMake(0, 452, 320, 28);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.0];
viewBotBar.frame = newFrameSize;
viewBotBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bottom-hidden.png"]];
// self.tabController.tabBar.hidden = YES;
[UIView commitAnimations];
}
else if (btnDwn.tag == 2) {
// perform your required functionality
btnDwn.tag = 1;
CGRect newFrameSize = CGRectMake(0, 402, 320, 79);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.0];
viewBotBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"1aa.png"]];
viewBotBar.frame = newFrameSize;
//self.tabController.tabBar.hidden = NO;
[UIView commitAnimations];
}
}
-(void)loc
{
LocationViewController *location = [[LocationViewController alloc]init];
[self.navigationController pushViewController:location animated:YES];
}
-(void)ser
{
ServicesViewController *services = [[ServicesViewController alloc]initWithNibName:#"ServicesViewController" bundle:nil];
[self.navigationController pushViewController:services animated:YES];
}
-(void)book
{
BookingViewController *book = [[BookingViewController alloc]initWithNibName:#"BookingViewController" bundle:nil];
[self.navigationController pushViewController:book animated:YES];
}
-(void)more
{
MoreViewController *more = [[MoreViewController alloc]initWithNibName:#"MoreViewController" bundle:nil];
[self.navigationController pushViewController:more animated:YES];
}
use
self.window.rootViewController = self.navController;
instead of
[self.window addSubview:self.navController.view];
see these custom UITabBar Demos Links..
Many Demos
PeekabooTabBarController
I am creating a app that display subview like ActionSheetView and in that i have added UIGridView and UIPageControll thru outlet , but now when i click the cell it does not respond ,my subview is a ViewController with the nib file.
and if i create a button and add in my popupview programmatically then it wil displaying, and also get the click event, but anything in outlet does not respond.
i have tried to set userinteraction enable in my subview but it does not done any good.
here is my code for first view that display subview by clicking barbutton:
- (void)popUpView:(id)sender {
//self.view.backgroundColor = [UIColor darkGrayColor];
bGView = [[UIView alloc] init]; /this is the background view and all view is added in it
bGView.frame = CGRectMake(0,0,320,490);
bGView.backgroundColor = [UIColor clearColor];
bGView.alpha = 0.8 ;
CGRect viewFrame = CGRectMake(10, 90, 300, 300);
aPopUpViewController = [[PopUpViewController alloc] initWithNibName:#"PopUpViewController" bundle:nil]; //this is my view controller and when this shows on screen it display my greed view
aPopUpViewController.view.frame = viewFrame;
aPopUpViewController.view.userInteractionEnabled = YES;
[bGView addSubview:aPopUpViewController.view];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
button.backgroundColor = [UIColor clearColor];
[button setBackgroundImage:[UIImage imageNamed:#"close_button.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(-1, 80, 30, 30);
[bGView addSubview:button];
//for view animation
/*
// from bottom to center animation
[bGView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[bGView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
[UIView commitAnimations];*/
//for page like effect
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
animations:^ { [self.view addSubview:bGView]; }
completion:nil];*/
/*CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionReveal; //choose your animation
[bGView.layer addAnimation:transition forKey:nil];
[self.view addSubview:bGView];*/
aPopUpViewController.view.userInteractionEnabled = YES;
bGView.userInteractionEnabled = YES;
self.view.userInteractionEnabled = YES;
bGView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
bGView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
[self.view addSubview:bGView];
addLabel.enabled = NO;
clipArt.enabled = NO;
emailItem.enabled = NO;
closeButton.enabled = NO;
self.navigationController.topViewController.title = #"Choose ClipArt";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"no";
}
- (void)aMethod:(id)sender
{
//[aPopUpViewController.view removeFromSuperview];
//[button removeFromSuperview];
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve//change to whatever animation you like
animations:^ { [bGView removeFromSuperview]; }
completion:nil];*/
[bGView removeFromSuperview];
addLabel.enabled = YES;
clipArt.enabled = YES;
emailItem.enabled = YES;
closeButton.enabled = YES;
self.navigationController.topViewController.title = #"Greeting's";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"yes";
}
and this is how my screen look like
UPDATE
now i figured out my problem,problem is that i have given my whole view a tap listner,now i am adding grid view as subview so when ever i tap on cell rather then do select cell it will generate view tap gesture and thats why cell never selected,that's what i think..
add this line after you add every subviews in your main view..
[self.view bringSubviewToFront:yourGridView];
I have tried the iCarousel, and add it to my project. I was able to put images. Now I'm trying to implement a method, that when the button was clicked the carousel will rotate.
I've tried this code:
- (IBAction) spinButton:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:carousel
cache:YES];
[spinButton removeFromSuperview];
[UIView commitAnimations];
}
But it seems to be that only the carousel view is animating.
Following two method to changes aries may be your problem being solve by this,
-(void)TappedButton:(UIButton *)sender{
UIView *view=[carousel itemViewAtIndex:sender.tag];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:YES];
// [spinButton removeFromSuperview];
[UIView commitAnimations];
NSLog(#"%d",sender.tag);
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"page.png"]] autorelease];
// label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
// label.backgroundColor = [UIColor clearColor];
// label.textAlignment = UITextAlignmentCenter;
// label.font = [label.font fontWithSize:50];
//
// [view addSubview:label];
UIButton *buttonForDisplay = [[[UIButton alloc] initWithFrame: view.bounds] autorelease];
buttonForDisplay.backgroundColor=[UIColor clearColor];
[buttonForDisplay setTitle:[NSString stringWithFormat:#"%d",index] forState:UIControlStateNormal];
buttonForDisplay.titleLabel.font = [label.font fontWithSize:50];
[buttonForDisplay addTarget:self action:#selector(TappedButton:) forControlEvents:UIControlEventTouchUpInside];
[buttonForDisplay bringSubviewToFront:view];
buttonForDisplay.tag = index;
/// view.tag=index;
[view addSubview:buttonForDisplay];
}
else
{
label = [[view subviews] lastObject];
}
//set label
// label.text = [[items objectAtIndex:index] stringValue];
return view;
}
EDIT
This method thru you can catch the reference of the carousel view.
- (UIView *)itemViewAtIndex:(NSInteger)index
Edit with Animation
UIViewController *nextViewController = [[UIViewController alloc] autorelease];
nextViewController.view.backgroundColor = [UIColor redColor];
CATransition *animation = [CATransition animation];
animation.duration = 3.5;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[self.navigationController pushViewController:nextViewController animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];
I would like to develop an app with a menu which looks like the ios Linkedin app one. Like this (the left picture)
There is 4 glimpses (miniatures) which are associated to the four principal views.
And the miniature always shows the updated state of the view.
I would like to know we can do a menu like this one ?
Thanks in advance for your help !
Sébastien ;)
So why do you put the 4 UIView in an other UIView and not directly on the UIViewController ?
And you talked about buttons but there are only UIView in your example ? I wonder if the 4 buttons are on the 4 views and are transparent in order to apply the transformation.
Do you have a code example for the transformation ?
Thanks a lot for your help !
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationItem setTitle:#"About us"];
presentationViewController = [[PresentationViewController alloc] initWithNibName:#"PresentationViewController" bundle:nil];
secteursViewController = [[SecteursViewController alloc] initWithNibName:#"SecteursViewController" bundle:nil];
engagementsViewController = [[EngagementsViewController alloc] initWithNibName:#"EngagementsViewController" bundle:nil];
interviewsViewController = [[InterviewsViewController alloc] initWithNibName:#"InterviewsViewController" bundle:nil];
presentationApercu = presentationViewController.view;
secteursApercu = secteursViewController.view;
videosApercu = interviewsViewController.view;
engagementsApercu = engagementsViewController.view;
presentationApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
presentationApercu.frame = CGRectMake(27., 18., presentationApercu.frame.size.width, presentationApercu.frame.size.height);
secteursApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
secteursApercu.frame = CGRectMake(185., 18., secteursApercu.frame.size.width, secteursApercu.frame.size.height);
videosApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
videosApercu.frame = CGRectMake(27., 196., videosApercu.frame.size.width, videosApercu.frame.size.height);;
engagementsApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
engagementsApercu.frame = CGRectMake(185., 196., engagementsApercu.frame.size.width, engagementsApercu.frame.size.height);
presentationApercu.tag = 1;
secteursApercu.tag = 2;
videosApercu.tag = 3;
engagementsApercu.tag = 4;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[presentationApercu addGestureRecognizer:tap];
[tap release];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[secteursApercu addGestureRecognizer:tap];
[tap release];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[videosApercu addGestureRecognizer:tap];
[tap release];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[engagementsApercu addGestureRecognizer:tap];
[tap release];
[self.view addSubview:presentationApercu];
[self.view addSubview:secteursApercu];
[self.view addSubview:videosApercu];
[self.view addSubview:engagementsApercu];
}
#pragma mark - IBActions
- (void)zoomReverse {
[self.navigationItem setLeftBarButtonItem:nil];
UITapGestureRecognizer *tap = nil;
switch (tagEnCours) {
case 1:
[self.view bringSubviewToFront:presentationApercu];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[presentationApercu addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
presentationApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
presentationApercu.frame = CGRectMake(27., 18., presentationApercu.frame.size.width, presentationApercu.frame.size.height);
[UIView commitAnimations];
break;
case 2:
[self.view bringSubviewToFront:secteursApercu];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[secteursApercu addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
secteursApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
secteursApercu.frame = CGRectMake(185., 18., secteursApercu.frame.size.width, secteursApercu.frame.size.height);
[UIView commitAnimations];
break;
case 3:
[self.view bringSubviewToFront:videosApercu];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[videosApercu addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
videosApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
videosApercu.frame = CGRectMake(27., 196., videosApercu.frame.size.width, videosApercu.frame.size.height);
[UIView commitAnimations];
break;
case 4:
[self.view bringSubviewToFront:engagementsApercu];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[engagementsApercu addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
engagementsApercu.transform = CGAffineTransformMakeScale(1/(320./107), 1/(367./122.));
engagementsApercu.frame = CGRectMake(185., 196., engagementsApercu.frame.size.width, engagementsApercu.frame.size.height);
[UIView commitAnimations];
break;
default:
break;
}
}
- (void)zoomAction:(UITapGestureRecognizer *)sender {
[self.navigationItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:#"About us" style:UIBarButtonItemStyleDone target:self action:#selector(zoomReverse)] autorelease]];
tagEnCours = sender.view.tag;
switch (sender.view.tag) {
case 1:
[self.view bringSubviewToFront:presentationApercu];
[presentationApercu removeGestureRecognizer:[presentationApercu.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
presentationApercu.transform = CGAffineTransformIdentity;
presentationApercu.frame = CGRectMake(0., 0., presentationApercu.frame.size.width, presentationApercu.frame.size.height);
[UIView commitAnimations];
break;
case 2:
[self.view bringSubviewToFront:secteursApercu];
[secteursApercu removeGestureRecognizer:[secteursApercu.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
secteursApercu.transform = CGAffineTransformIdentity;
secteursApercu.frame = CGRectMake(0., 0., secteursApercu.frame.size.width, secteursApercu.frame.size.height);
[UIView commitAnimations];
break;
case 3:
[self.view bringSubviewToFront:videosApercu];
[videosApercu removeGestureRecognizer:[videosApercu.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
videosApercu.transform = CGAffineTransformIdentity;
videosApercu.frame = CGRectMake(0., 0., videosApercu.frame.size.width, videosApercu.frame.size.height);
[UIView commitAnimations];
break;
case 4:
[self.view bringSubviewToFront:engagementsApercu];
[engagementsApercu removeGestureRecognizer:[engagementsApercu.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
engagementsApercu.transform = CGAffineTransformIdentity;
engagementsApercu.frame = CGRectMake(0., 0., engagementsApercu.frame.size.width, engagementsApercu.frame.size.height);
[UIView commitAnimations];
break;
default:
break;
}
}
I think that this application is structured as follows:
UIViewController
| UIView
| UIView
| UIView
| UIView
| UIView
The first contains the main view controller (the one containing the 4 buttons), these are reduced by (I assume) a transform and then the View is superimposed by a view of the secondary, the second requirement.
This is what I think, because if you try to scroll the table and immediately go back, even in the thumbnail view scrolling.
Hope that was of some help.
Consider this as a draft from which to take inspiration:
//.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#end
//.m
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic, strong) UIView *v1;
#property (nonatomic, strong) UIView *v2;
#property (nonatomic, strong) UIView *v3;
#property (nonatomic, strong) UIView *v4;
#end
#implementation ViewController
#synthesize v1 = _v1;
#synthesize v2 = _v2;
#synthesize v3 = _v3;
#synthesize v4 = _v4;
- (void)viewDidLoad {
[super viewDidLoad];
_v1 = [[UIView alloc] initWithFrame:self.view.bounds];
_v2 = [[UIView alloc] initWithFrame:self.view.bounds];
_v3 = [[UIView alloc] initWithFrame:self.view.bounds];
_v4 = [[UIView alloc] initWithFrame:self.view.bounds];
[_v1 setBackgroundColor:[UIColor redColor]];
[_v2 setBackgroundColor:[UIColor yellowColor]];
[_v3 setBackgroundColor:[UIColor blueColor]];
[_v4 setBackgroundColor:[UIColor greenColor]];
_v1.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v1.frame = CGRectMake(10., 10., _v1.frame.size.width, _v1.frame.size.height);
_v2.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v2.frame = CGRectMake(170., 10., _v2.frame.size.width, _v2.frame.size.height);
_v3.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v3.frame = CGRectMake(10., 240., _v3.frame.size.width, _v3.frame.size.height);
_v4.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v4.frame = CGRectMake(170., 240., _v4.frame.size.width, _v4.frame.size.height);
_v1.tag = 1;
_v2.tag = 2;
_v3.tag = 3;
_v4.tag = 4;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v1 addGestureRecognizer:tap];
[tap release];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v2 addGestureRecognizer:tap];
[tap release];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v3 addGestureRecognizer:tap];
[tap release];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v4 addGestureRecognizer:tap];
[tap release];
[self.view addSubview:_v1];
[self.view addSubview:_v2];
[self.view addSubview:_v3];
[self.view addSubview:_v4];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(10, 10, 100, 30)];
[btn setTitle:#"Close" forState:UIControlStateNormal];
btn.tag = 1;
[btn addTarget:self action:#selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside];
[_v1 addSubview:btn];
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(10, 10, 100, 30)];
[btn setTitle:#"Close" forState:UIControlStateNormal];
btn.tag = 2;
[btn addTarget:self action:#selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside];
[_v2 addSubview:btn];
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(10, 10, 100, 30)];
[btn setTitle:#"Close" forState:UIControlStateNormal];
btn.tag = 3;
[btn addTarget:self action:#selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside];
[_v3 addSubview:btn];
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(10, 10, 100, 30)];
[btn setTitle:#"Close" forState:UIControlStateNormal];
btn.tag = 4;
[btn addTarget:self action:#selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside];
[_v4 addSubview:btn];
}
- (void)zoomReverse:(UIButton *)sender {
UITapGestureRecognizer *tap = nil;
switch (sender.tag) {
case 1:
[self.view bringSubviewToFront:_v1];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v1 addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v1.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v1.frame = CGRectMake(10., 10., _v1.frame.size.width, _v1.frame.size.height);
[UIView commitAnimations];
break;
case 2:
[self.view bringSubviewToFront:_v2];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v2 addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v2.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v2.frame = CGRectMake(170., 10., _v2.frame.size.width, _v2.frame.size.height);
[UIView commitAnimations];
break;
case 3:
[self.view bringSubviewToFront:_v3];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v3 addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v3.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v3.frame = CGRectMake(10., 240., _v3.frame.size.width, _v3.frame.size.height);
[UIView commitAnimations];
break;
case 4:
[self.view bringSubviewToFront:_v4];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(zoomAction:)];
[tap setNumberOfTapsRequired:1];
[_v4 addGestureRecognizer:tap];
[tap release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v4.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.));
_v4.frame = CGRectMake(170., 240., _v4.frame.size.width, _v4.frame.size.height);
[UIView commitAnimations];
break;
default:
break;
}
}
- (void)zoomAction:(UITapGestureRecognizer *)sender {
switch (sender.view.tag) {
case 1:
[self.view bringSubviewToFront:_v1];
[_v1 removeGestureRecognizer:[_v1.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v1.transform = CGAffineTransformIdentity;
_v1.frame = CGRectMake(0., 0., _v1.frame.size.width, _v1.frame.size.height);
[UIView commitAnimations];
break;
case 2:
[self.view bringSubviewToFront:_v2];
[_v2 removeGestureRecognizer:[_v2.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v2.transform = CGAffineTransformIdentity;
_v2.frame = CGRectMake(0., 0., _v2.frame.size.width, _v2.frame.size.height);
[UIView commitAnimations];
break;
case 3:
[self.view bringSubviewToFront:_v3];
[_v3 removeGestureRecognizer:[_v3.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v3.transform = CGAffineTransformIdentity;
_v3.frame = CGRectMake(0., 0., _v3.frame.size.width, _v3.frame.size.height);
[UIView commitAnimations];
break;
case 4:
[self.view bringSubviewToFront:_v4];
[_v4 removeGestureRecognizer:[_v4.gestureRecognizers objectAtIndex:0]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_v4.transform = CGAffineTransformIdentity;
_v4.frame = CGRectMake(0., 0., _v4.frame.size.width, _v4.frame.size.height);
[UIView commitAnimations];
break;
default:
break;
}
}
- (void)viewDidUnload {
[super viewDidUnload];
[self setV1:nil];
[self setV2:nil];
[self setV3:nil];
[self setV4:nil];
}
#end
I hope it can help.
How to give animation to UIImageView.
I have a following code for animation .but not working for imageview
MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)];
MyImage.image=[UIImage imageNamed:#"image.png"];
MyImage.userInteractionEnabled = YES;
[self.view addSubview:MyImage];
[UIView beginAnimations : nil context : nil];
[UIView setAnimationCurve : UIViewAnimationCurveLinear];
[UIView setAnimationDuration : 1.00];
UIView setAnimationTransition : UIViewAnimationTransitionFlipFromLeft forView : MyImage cache : YES];
[UIView commitAnimations];
Anybody have idea let me know ..Thanks
UIView setAnimationTransition : UIViewAnimationTransitionFlipFromLeft forView : MyImage cache : YES];
Loose [ before the code? Maybe it's the type mistake.
And I think you may like this one, block-based animation is better ;) :
[UIView transitionFromView:self.view
toView:MyImage
duration:1.0f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];
And here's code snippet that works well:
MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)];
MyImage.image=[UIImage imageNamed:#"NTCHomeMainPic.png"];
MyImage.userInteractionEnabled = YES;
// [self.view addSubview:MyImage]; // You don't need to add it as subview, but never mind
[UIView transitionFromView:self.view
toView:MyImage
duration:1.0f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];
Edit:
You need to create a new view and add the MyImage to it. New version below:
UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[newView setBackgroundColor:[UIColor whiteColor]];
UIImageView * MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)];
MyImage.image=[UIImage imageNamed:#"NTCHomeMainPic.png"];
MyImage.userInteractionEnabled = YES;
[newView addSubview:MyImage];
[UIView transitionFromView:self.view
toView:newView
duration:1.0f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];