I want to hide some views with animation in my app on click similar to Grafio app as shown in image below. Could you please give me some direction to achieve this.
make two triangular shaped images first for up direction and another for down direction say up.png and down.png
then set both images for different control states like....
[btn setBackgroundImage:[UIImage imageNamed:#"down.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:#"up.png"] forState:UIControlStateSelected];
now in IBAction of that button write...
- (IBAction)onEnterQtySaveClick:(id)sender
{
UIButton *button = (UIButton *)sender;
if (button.selected)
{
// move up the menuView
[UIView animateWithDuration:0.3 animations:^{
[self.menuView setFrame:CGRectMake(0, 0, 320, 50)];
}];
}
else
{
// move down the menuView
[UIView animateWithDuration:0.3 animations:^{
[self.menuView setFrame:CGRectMake(0, 50, 320, 50)];
}];
}
button.selected = !button.selected;
}
Hope you will like this and it will solve your and many more's problem
Related
So, at the moment, I am attempting to pass the same UINavigationBar to multiple UIViewControllers.
For example, say I have a UINavigationController whose view is a UIViewController's UIView. Withinn the custom UIViewController's UIView I modify the contents of the UINavigationBar's titleview.
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x + 50, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width - 100, 44)];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(35, titleView.frame.origin.y + 2, 40, 40);
[button1 setImage:[UIImage imageNamed:#"FacebookFriendRequestIcon.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:#selector(FriendRequestsPopover:) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:button1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(80, titleView.frame.origin.y + 2, 40, 40);
[button2 setImage:[UIImage imageNamed:#"FacebookMessagesIcon.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:#selector(MessagesPopover:) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:button2];
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(125, titleView.frame.origin.y + 2, 40, 40);
[button3 setImage:[UIImage imageNamed:#"FacebookNotificationsIcon.png"] forState:UIControlStateNormal];
[button3 addTarget:self action:#selector(NotificationsPopover:) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:button3];
self.navigationItem.titleView = titleView;
When a user presses a button within the UIViewcontroller (not referring to the navigationBar's items), the user is then pushed to another UIViewController:
GeneralInfoViewController *generalInformationController = [[GeneralInfoViewController alloc] init];
[self.navigationController pushViewController:generalInformationController animated:YES];
UIViewController1(UINavigationController) pushes to UIViewController2(UINavigationController)
So, the generalInformationController is subclassed as a UIViewController. Now when the push occurs, I would like an animation to occur, but only with the UIView's not with the NavigationBar.
An example application would be like Facebook, the Navigationbar's middle buttons (messages, friend requests, and notifications) are ALWAYS visibile and never animate away when a viewcontroller is pushed onto the stack.
Anyone have any ideas on how this is done? I guess a theoretical answer would be nice but a coding example would be nicer :)
An example application would be like Facebook, the Navigationbar's
middle buttons (messages, friend requests, and notifications) are
ALWAYS visibile and never animate away when a viewcontroller is pushed
onto the stack.
That might be a clue that the Facebook app doesn't use a navigation controller. I don't know if it does or doesn't, but it would probably be easier to write your own container view controller that does what you want than to try to force UINavigationController to behave in a way that it's not designed to.
If you use navigation controller for pushing and poping, you can't make, that your nag bar stay on his place;
BUT you can try it:
newView.bounds = mainView.bounds; //newView can be nextViewController.view
newView.biunds.size.height=newView.biunds.size.height-self.navBar.bounds.size.height; //devide navBar height
newView.frame = CGRectMake(newView.frame.origin.x + 784, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height);
[mainView addSubview:newView];
/* Begin transition */
[UIView beginAnimations:#"Slide Left" context:oldView];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.0f];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDidStopSelector:#selector(slideInCompleted:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
newView.frame = CGRectMake(0,0, newView.frame.size.width, newView.frame.size.height);
oldView.frame = CGRectMake(oldView.frame.origin.x - 784, oldView.frame.origin.y, oldView.frame.size.width, oldView.frame.size.height);
[UIView commitAnimations];
Post comments, for your result.
I have created a custom button in viewDidLoad() Method and set Autoresizingmask. It works well. But When I Put the same code in Button Click event It Doesn't Autoresized. Is there anyother way to access the AutoresizingMask within Click Events? Thanks in Advance.
Enter code here
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.backgroundColor=[UIColor redColor];
button.frame=CGRectMake(20, 373, 73, 43);
button.autoresizingMask=(UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth);
[self.view addSubview:button];
}
-(IBAction)btn_clicked
{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:#"Dynamic Btn" forState:UIControlStateNormal];
enter code here
btn.backgroundColor=[UIColor yellowColor];
btn.frame=CGRectMake(20, 150, 73, 43);
btn.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:btn];
}
(void)layoutSubviews
The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.
Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.
You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded method.
With reference to Apple document in case of AutoresizingMask not working we need override the above method. AutoresizingMask works when the view frame is changed within - (void)layoutSubviews.
enter code here
-(void)layoutSubviews
{
NSLog(#"layoutSubviews called");
CGRect viewsize=[[UIScreen mainScreen]bounds];
view.frame=CGRectMake(0, 0, 320, viewsize.size.height);
}
Trying the Above code Your AutoresizingMask works well in both iPhone4 and iPhone5.
(void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame=CGRectMake(20, 73, 173, 43);
[button addTarget:self action:#selector(btn_clicked:)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:button];
}
-(IBAction)btn_clicked:(id)sender
{
UIButton btn = (UIButton)sender;
[btn setTitle:#"Dynamic" forState:UIControlStateNormal];
[UIView animateWithDuration: 0.4
animations: ^{
btn.frame=CGRectMake(20, 73, 100, 43);
[UIView commitAnimations];
}completion: ^(BOOL finished){
}];
}
i think you need to typecast your UIButton through its click event. make your touchUpInside event like this
-(IBAction)btn_clicked:(id)sender
{
UIButton *btn = (UIButton*)sender;
[btn setTitle:#"Dynamic Btn" forState:UIControlStateNormal];
//enter code here
btn.backgroundColor=[UIColor yellowColor];
btn.frame=CGRectMake(20, 150, 73, 43);
btn.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:btn];
}
And call this click like this #selector(btn_clicked:) or connect it via Interface Builder
See if this work....
Please use below code may help you:
-(IBAction)btn_clicked
{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:#"Dynamic Btn" forState:UIControlStateNormal];
btn.backgroundColor=[UIColor yellowColor];
btn.frame=CGRectMake(20, 150, 73, 43);
btn.autoresizesSubviews = YES;
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
btn.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:btn];
}
I'm creating a hidden form containing 3 buttons at the bottom of the parent view, by pressing another button, the view becomes visible, but those 3 buttons are not pressed, I don `t know what the problem is.
I add a button via code. Here is a method that is called when the button is pressed.
- (IBAction) addData:(id)sender
{
if(attachInfo==nil){
float screenHeight = self.view.frame.size.height;
attachInfo=[[UIView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, 216)];
UIButton *attachImage = [UIButton buttonWithType:UIButtonTypeCustom];
//attachImage.enabled = YES;
[attachImage addTarget:self action:#selector(addImage:) forControlEvents:UIControlEventTouchUpInside];
[attachImage setFrame:CGRectMake(20, 20, 0, 0)];
[attachImage setImage:[UIImage imageNamed:#"add_photos"] forState:UIControlStateNormal];
[attachImage sizeToFit];
[attachInfo addSubview:attachImage];
UIButton *attachDoc = [UIButton buttonWithType:UIButtonTypeCustom];
//[pushButton addTarget:self action:#selector(pushViewController) forControlEvents:UIControlEventTouchUpInside];
[attachDoc setFrame:CGRectMake(120, 20, 80, 80)];
[attachDoc setImage:[UIImage imageNamed:#"add_docs.png"] forState:UIControlStateNormal];
[attachDoc sizeToFit];
[attachInfo addSubview:attachDoc];
UIButton *attachPlace = [UIButton buttonWithType:UIButtonTypeCustom];
//[pushButton addTarget:self action:#selector(pushViewController) forControlEvents:UIControlEventTouchUpInside];
[attachPlace setFrame:CGRectMake(220, 20, 80, 80)];
[attachPlace setImage:[UIImage imageNamed:#"add_place.png"] forState:UIControlStateNormal];
[attachPlace sizeToFit];
[attachInfo addSubview:attachPlace];
//[self.view addSubview:attachInfo];
[self.view addSubview:attachInfo];
[UIView animateWithDuration:0.3f animations:^{
CGRect frame = attachInfo.superview.frame;
frame.origin.y -= 216;
attachInfo.superview.frame=frame;
}];
}
else
{
[UIView animateWithDuration:0.3f animations:^{
CGRect frame = attachInfo.superview.frame;
frame.origin.y += 216;
attachInfo.superview.frame=frame;
}];
attachInfo=nil;
}
}
you need to add Action of buttons.
- (IBAction)first:(id)sender;
{
firstViewController * fvc=[FirstViewController alloc]init];
[FirstButton setHidden:False];
[self.navigationController pushViewController:fvc animated:YES];
}
- (IBAction)Second:(id)sender;
{
SecondViewController * svc=[SecondViewController alloc]init];
[SecondButton setHidden:False];
[self.navigationController pushViewController:svc animated:YES];
}
- (IBAction)Third:(id)sender;
{
ThirdViewController * tvc=[ThirdViewController alloc]init];
[ThirdButton setHidden:False];
[self.navigationController pushViewController:fvc animated:YES];
}
In the first button (attachImage), the height and the width is zero. So it should not be visible. For the other two buttons you haven't set the target. So those are not clickable.
for the first button set
[attachImage setFrame:CGRectMake(20, 20, 80, 80)];
and for the other two buttons add
//for the second button
[attachDoc addTarget:self action:#selector(addImage:) forControlEvents:UIControlEventTouchUpInside];
//for the third button
[attachPlace addTarget:self action:#selector(addImage:) forControlEvents:UIControlEventTouchUpInside];
-(void)createHiddenForm
{
hiddenView = [[UIView alloc] initWithFrame:CGRectMake(0,100,320,300)];
[hidden setHidden:TRUE];
[self.view addSubview:hiddenView];
float posY = 50.0;
for (int i=0 ; i<3 ; i++)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(50,posY, 100, 50)];
[button addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[hiddenView addSubview:button];
posY=posY+60;
}
}
-(void)showHiddenView
{
hidden.hidden = FALSE;
[self.view bringSubviewToFront:hiddenView];
}
-(void)buttonClicked:(id)sender
{
UIButton *senderBtn = (UIButton *)sender;
NSLog(#"Sender Button's tag = %#",senderBtn.tag);
}
Hope it will help you.
float screenHeight = self.view.frame.size.height;
attachInfo=[[UIView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, 216)];
From the above, u r adding the attachInfo Y position outside the view boundaries.
Button onclick won't work when added outside the view.
To make it work replace below line.
[UIView animateWithDuration:0.3f animations:^{
CGRect frame = attachInfo.superview.frame;
frame.origin.y -= 216;
attachInfo.superview.frame=frame;
Instead of moving superview frame move attachInfo frame like this.
[UIView animateWithDuration:0.3f animations:^{
CGRect frame = attachInfo.frame;
frame.origin.y -= 216;
attachInfo.frame=frame;
So that attachInfo view will be added to the super view boundaries with animation.
Below is the code where I show a UIView from under a toolbar. It is displayed by clicking a button on toolbar. Now I want to add a button to the UIView that pops up , so as to cancel it. If possible a button over navigation bar which makes the UI better?
Can anyone point me towards a tutorial or so?
-(void)likeButton:(UIBarButtonItem *)button
{
CGRect frame = CGRectMake(0, 480, 320, 190);
frame.origin.y = CGRectGetMaxY(self.optionsToolBar.frame)-frame.size.height;
bottomView.frame = frame;
[self.optionsToolBar.superview insertSubview:bottomView
belowSubview:self.optionsToolBar];
}
-(void)likeButton:(UIBarButtonItem *)button
{
CGRect frame = CGRectMake(0, 480, 320, 190);
frame.origin.y = CGRectGetMaxY(self.optionsToolBar.frame)-frame.size.height;
bottomView.frame = frame;
UIView *navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationView setBackgroundColor:[UIColor blueColor]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:#"close" forState:UIControlStateNormal];
[button addTarget:self action:#selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
[navigationView addSubView:button];
[bottomView addSubView:navigationView];
[self.optionsToolBar.superview insertSubview:bottomView
belowSubview:self.optionsToolBar];
}
- (void) closeView :(id)sender{
[[sender superView] removeFromSuperView];
}
I want a button that has a another button on the backside. When you press the button it should flip horizontal and show the other button. Apple did this in the ipod-App. When you hear a song you can press the button on the right site of the navigationbar and then the view flips and you can see all the songs from the album. But the interest point is that the button on the right side flips with the view horizontal.
How can I do this?
alt text http://img51.imageshack.us/img51/585/welyrics2jpg.png
Thanks for the answer!
I dont understand this atm.
My iPhone coach did it for me a while back.. but i wasnt looking at what he did.
So heres the code.
.h
#import <UIKit/UIKit.h>
#interface flipTesViewController : UIViewController {
IBOutlet UIView *containerView;
UIImageView *heads;
UIImageView *tails;
}
-(IBAction)test;
#end
.m
#import "flipTesViewController.h"
#implementation flipTesViewController
-(IBAction)test{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(test)];
[UIView setAnimationDuration:.5];
if(heads.tag==1){
[containerView addSubview:heads];
heads.tag=2;
}
else{
[containerView addSubview:tails];
heads.tag=1;
}
[UIView commitAnimations];
}
- (void)viewDidLoad {
[super viewDidLoad];
heads = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"NZHeads.png"]];
tails = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"NZTails.png"]];
[containerView addSubview:heads];
}
//other method built in to view based template
#end
On 3.x there's a simpler way:
Make the "backside view" as a UIViewController or one of its subclasses.
When the your "flip" button is pressed, call
.
backsideViewCtrler.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:backsideViewCtrler animated:YES];
-(void)viewDidLoad
{
UIButton *btn; = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(x, y, 60, 40);
btn.backgroundColor = [UIColor clearColor];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
btn.tag=count;
[buttonWithTag setBackgroundImage:[UIImage imageNamed:#"2.png"] forState:UIControlStateNormal];
[btn setTitle:[NSString stringWithFormat:#"%d",btn.tag] forState:UIControlStateNormal];
[view_frame addSubview:btn];
[btn addTarget:self action:#selector(Click:)forControlEvents:UIControlEventTouchUpInside];
}
//action
- (IBAction)Click:(id)sender
{
UIButton *click_btn = (UIButton *)sender;
NSLog(#"%d",click_btn.tag);
UIButton *buttonWithTag = (UIButton *)[view_frame viewWithTag:click_btn.tag];
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 1.0;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = #"oglFlip";
[buttonWithTag.layer addAnimation:animation forKey:nil];
[buttonWithTag setBackgroundImage:[UIImage imageNamed:#"1.png"] forState:UIControlStateNormal];
}