-3

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

} 
Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
saravanaa
  • 9
  • 9
  • 2
    possible duplicate of [how to implement a pop up dialog box in iOS](http://stackoverflow.com/questions/4988564/how-to-implement-a-pop-up-dialog-box-in-ios) – Scott Solmer Mar 18 '15 at 12:33
  • No i dnt need dialog box.. i need the view want to popup.. when the button click.. – saravanaa Mar 18 '15 at 12:35

3 Answers3

0

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) {
    }];
}
IxPaka
  • 1,990
  • 1
  • 16
  • 18
  • wen i click the button i refuse the alpha value of the uiviewcontroller.. i need the login view want to display like pop... help me.. – saravanaa Mar 18 '15 at 12:49
  • @saravanaa what do you mean you refuse alpha value of uiviewcontroller? uiviewcontroller doesnt have an alpha value, its view does. Alpha = 0 means view wont be visible, setting it to 1 with animation will slowly make it fully visible. Isnt that what you wanted? – IxPaka Mar 18 '15 at 12:53
0

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.

  • I have shown you the hierarchy of how it should look like and how to implement the same. first part shows hierarchy and text inside braces indicates its parent. implement this first and then follow the other coding part. If u still have doubts feel free to ask. – Priyanka Wadher Mistry Mar 19 '15 at 05:15
-2

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
}];
}
Atif Imran
  • 1,899
  • 2
  • 18
  • 33