0

I am facing a weird situation. I have a tab bar application,where i am showing a custom alertbox in a particular view.The problem is that the alertbox always display on top rather than middle of screen.

I am currently using Xcode 3.2.5 & build it on iPhone simulator 4.2 enter image description here

Edit

-(void)createAlertbox{

    alertView = [[UIAlertView alloc] init];
    [alertView setDelegate:self];
    [alertView setTag:1];
    [alertView setTitle:@"sample"];
    [alertView setMessage:@" "];
    [alertView addButtonWithTitle:@"Enter"];

    CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0,60.0);
    [alertView setTransform: moveUp];
    ageTextField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0,25.0)];
    [ageTextField setBackgroundColor:[UIColor whiteColor]];
    [ageTextField setPlaceholder:@"Enter your Current Age"];
    ageTextField.keyboardType=UIKeyboardTypeNumberPad;
    ageTextField.delegate=self;
    [alertView addSubview:ageTextField];

    [alertView show];
    [alertView release];
    [ageTextField release]; 

}
raaz
  • 12,410
  • 22
  • 64
  • 81
  • Thats because of that CGAffineTransform – Felix Jan 26 '11 at 14:59
  • sorry,i comment out CGAffineTransform, now it is slide very little downward i.e.just below navigation bar & still it is showing on top. – raaz Jan 26 '11 at 15:18

1 Answers1

0

I don't know why phix23 did't put that comment as an answer!

It's because of the transform :

CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0,60.0);
[alertView setTransform: moveUp];

You're telling the ui alert view to be 60px higher than it would otherwise be. Delete these lines and I bet it's in the center again.


Where did you get your code from - I'm assuming that because you didn't know what the transform did you have cut-and-pasted it from somewhere?

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • Actually,i use CGAffineTransform to adjust the alert view position after the keyboard showing in the view & after comment out CGAffineTransform now the alert view not changing its position when the keyboard appear.The alert view is slide very little downward i.e.just below navigation bar & still it is showing on top – raaz Jan 26 '11 at 15:31
  • I am refering to this post of SO http://stackoverflow.com/questions/376104/uitextfield-in-uialertview-on-iphone-how-to-make-it-responsive – raaz Jan 26 '11 at 15:39