Popup the uiview in button click in iOS - 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
}];
}

Related

Custom UIActivityViewController-like view that slides up and down

Is there a way to subclass or customize UIActivityViewController to create a sort of custom view? For example, see the image below from the app Overcast. I want to create a view similar to that, where if you tap a button, the view pops up and when you tap outside of the view, it slides back down.
Why not use an UIView ? Set it's initial frame's y value to -self.customView.frame.size.height and animate it's frame to the normal position using [UIView animateWithDuration]
-(void)showCustomView{
[self.customview setFrame:CGRectMake(0, -self.customView.frame.size.height, self.view.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.bounds.size.height-self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
-(void)hideCustomView{
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.customView.frame.size.height, self.customView.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
Add an UITapGestureRecognizer and call hideCustomView when tapped outside the customView

How to flip a view with a label on the front side and another label on the back side - see image

How can I flip a view with a label on the front side and another label on the back side when a button is clicked? Something that looks like the image below.
What would be the logic to create this effect?
Thanks
EDIT:
Sorry about the confusion but please note that I'm just talking about a view not ViewControllers, this effect will happen within the same viewController. I have updated the image to reflect that the view I'm talking about is a subView inside the main view.
I too had something very similar situation, on click of a button on ViewController1 I have to move to another ViewController2. I used this code,
//code this in ViewController1
-(IBAction)flipView:(id)sender
{
ViewController2 *view2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[[self navigationController] pushViewController:view2 animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[view2 release];
}
//code this in ViewController2 on click of back button
-(IBAction)flipView:(id)sender
{
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[[self navigationController] popViewControllerAnimated:YES];
[UIView commitAnimations];
}
But in this code I am using 2 classes, if it is fine to you, use this code. Hopes it solves your problem to some extent.
What you can do is use two UIViews, one for the first side, one for the second side.
Show the first view, hide the second view, and set the second view's frame to have a width of 0.
Then, when your first view is visible, animate its frame to have a width equal to 0. Hide the first view, unhide the second view, and animate the second view's frame to the desired frame.
Edit : This does not appear to work well if you have labels in your views, as this is a 2D flip. Sorry about that. #Maverick's answer could work pretty well in your case.
Call this method in your viewController, your viewController view flips and viewController life cycle method calls and simply change the image of UIImageView you want to display in
-(void)viewdidload method.
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Please vote up if you find it helping

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.

UIButton turnover animation

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...

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