UIButton turnover animation - ios

Do any of you know how I could possibly add an animation that is triggered when a UIButton is pressed, and the UIButton turns aand enlarges at the same time, and on the other side I can show another view? A bit like in dashboard on a Mac, with the info button on the widgets...

You can use transitions:
[UIView transitionWithView:containerView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
buttonView.hidden = YES;
otherView1.hidden = NO;
otherView2.hidden = NO;
otherViewEtc.hidden = NO;
} completion:nil];
You would then have a containerView which contains the flip button and the alternate view hidden, and in the transition, you can hide the first view and show the alternate view...

Related

Popup the uiview in button click in iOS

I have one mainview UIViewController. in that view put one UIView name loginview with small size(self.loginview.frame = CGRectMake(4,166,306,153);
In mainview uiviewcontroller i put one button if i click that button loginview want to display like popup... how can i achieve this help me here code.
- (IBAction)Regbtn_click:(id)sender
{
//in this place i want to write the code for login view want come like popup.. help me..
loginview.hidden=false
}
Instead of setting hidden property of your loginview, set its alpha to 0.0 and you can use this animation
-(IBAction)Regbtn_click:(id)sender {
//[self.view addSubview:self.loginView]; if your loginview is not added to view, if it is, ignore this line
[UIView animateWithDuration:0.5 animations:^{
self.loginView.alpha = 1.0; //to display loginview
} completion:^(BOOL finished) {
}];
}
You can animate the view with two animations:
1) scaling
2) fading
View Controller
->Button (Viewcontroller Child)
->LoginWrapperView (Viewcontroller Child)
->black-transparent View (LoginWrapperView Child)
->login View (LoginWrapperView Child)
Add black semi-transparent view (with opacity of 0.2 i think) on screen and above that place your loginView and set its opacity to 0.
[LoginWrapperView SetHidden:YES];
[loginView SetAlpha:0];
[loginView SetFrame:CGRectMake(0,0,0,0)];
Now when you click on the button,
[LoginWrapperView SetHidden:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self];
//position on screen
[loginView SetAlpha:1];
[loginView SetFrame:<your CGRect goes here>];
[UIView setAnimationDidStopSelector:#selector(finishAnimation:finished:context:)];
//animate off screen
[UIView commitAnimations];
Then handle Tap Getsture on semi-transparent view to close or hide the same by reversing the same animation with different values.
You can push your view modally or use a nice library like MZFormSheetController that do just that.
Here's how it looks like
It is simple just present your view. You could also make the background transparent and many other customization.
YourPopupViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PopupView"];
-(IBAction)buttonClick{
// present form sheet with view controller
[self mz_presentFormSheetController:vc animated:YES completionHandler:^(MZFormSheetController *formSheetController) {
//do your login stuff
}];
}

Fade UIBarButtonItem When Swapped

When I change my UIBarButtonItems they change abruptly, unlike the default which gives a nice but speedy fade animation. You can see this when segueing between view controllers, for instance, the back button will fade in and out. How can I simulate the same effect?
Update - Based on this answer - https://stackoverflow.com/a/10939684/2649021
It looks like you would have to do something like this to make the button itself fade out.
[self.navigationItem setRightBarButtonItem:nil animated:YES];
And do something like this to make it fade in
[self.navigationItem setRightBarButtonItem:myButton animated:YES];
Otherwise if you want more control over animation properties you would have to create a custom view I believe.
EDIT: I just confirmed that you can fade a UIBarButtonItem custom view using this.
As a test I created a simple project and dropped a UIBarButtonItem onto the navigation bar. I created an outlet to the view controller. In viewDidLoad on the view controller I setup a custom view
-(void)viewDidLoad{
[super viewDidLoad];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,40,40)];
lbl.text = #"test";
UIView *customView = [[UIView alloc]initWithFrame:CGRectMake(0,0,40,40)];
[customView addSubview:lbl];
self.barButtonItem.customView = customView;
}
As a test in viewDidAppear I animated it
-(void)viewDidAppear:(BOOL)animated
{
[UIView animateWithDuration:3.0
delay:3.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.barButtonItem.customView.alpha = 0;
}
completion:^(BOOL finished) {
NSLog(#"animation complete");
}];
EDIT: Here's a link to Apples Documentation for a full explanation of UIView animations.
https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html
You might have to create a custom bar button item using a view or an image, and then animate the properties of the view as digitalHound shows.

Present a view with animation

Instead of doing self.view = view; like I am currently I want to present this view with animation. It is not an entire view controller but just a view, I am just replacing the current view with this view on a button click.
Is there anyway to do this animated?
Thanks in advance.
Try something like:
UIView *newView = ...;
// new view is added as a subview somewhere
newView.alpha = 0;
[UIView animateWithDuration:1
animations:^{
newView.alpha = 1;
}];
Which will fade the view in. You could also look at animateWithDuration:delay:options:animations:completion: which provides other animation options. Or transitionFromView:toView:duration:options:completion:.

how to add animation to a second view which is inside first view in xcode for ipad using storyboard

In storyboard, in a view controller i've added a scroll view.Inside it another two different views are added & named them as "firstview" & "secondview". When i press add button from "firstview" ,it will show SecondView which is kept as hidden during the initial run. Now i want to display that view by performing some animations. How to solve this?
[UIView transitionWithView:self.secondview
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.secondview.alpha = 1.0f;
} completion:NULL];
tried these but not working
Thanks in advance....
Try the following code if your second view is hidden
[UIView transitionWithView:self.secondview duration:5.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.secondview.hidden = NO;
} completion:^(BOOL finished) {
self.secondview.alpha = 1.0f;
}];
If your self.secondview is hidden then you need to make it unhidden and set the alpha to 0. If the secondview is hidden that doesn't mean it's alpha is 0.
So use the same code but instead of make it hidden set the secondview.alpha = 0; or in your case make it from the storyboard.

Default iOS UINavigationBar animation isn't smooth

I'm working on an application and need to hide the UINavigationBar (and toolbar) to provide a fullscreen mode in the in-app browser.
When the app run this code the animation work just fine.
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
When I want to exit from the full-screen mode the animation isn't smooth at all.
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController setToolbarHidden:NO animated:YES];
During the animation a black rectangle is visible under the navigation bar, I think it is the UIWebView that resize itself (the toolbar animation work just fine.)
Any idea on how I can solve this problem?
Instead of using setNavigationBarHidden:animated: for hiding the navigation bar, try this:
In your view controller's viewDidLoad compute different frames for your navigation bar and your view:
// The normal navigation bar frame, i.e. fully visible
normalNavBarFrame = self.navigationController.navigationBar.frame;
// The frame of the hidden navigation bar (moved up by its height)
hiddenNavBarFrame = normalNavBarFrame;
hiddenNavBarFrame.origin.y -= CGRectGetHeight(normalNavBarFrame);
// The frame of your view as specified in the nib file
normalViewFrame = self.view.frame;
// The frame of your view moved up by the height of the navigation bar
// and increased in height by the same amount
fullViewFrame = normalViewFrame;
fullViewFrame.origin.y -= CGRectGetHeight(normalNavBarFrame);
fullViewFrame.size.height += CGRectGetHeight(normalNavBarFrame);
When you want to go fullscreen:
[UIView animateWithDuration:0.3
animations:^{
self.navigationController.navigationBar.frame = hiddenNavBarFrame;
self.view.frame = fullViewFrame;
} completion:^(BOOL finished) {
}];
When you want to return to normal:
[UIView animateWithDuration:0.3
animations:^{
self.navigationController.navigationBar.frame = normalNavBarFrame;
self.view.frame = normalViewFrame;
} completion:^(BOOL finished) {
}];
Tested this in the iOS 5.1 emulator. Hope you can use that. The "black rectangle" must be the default background color of your window, i.e. a gap between your navigation bar and your view.

Resources