1

i was implement a custom alert view from

http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html

but i want to make that custom alert view rotate when the device orientation change. when i run that application at the first time in portrait orientation of iphone simulator, the custom alert view orientation is landscape, but when i rotate the device into landscape left, the custom alert view orientation is landscape. After rotating the device in many ways, i found that the custom alert orientation is follow suit the home button position..

i was implement this several methods :

-(void) willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"kkksksksk");    

}

-(void) willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 NSLog(@"aaa"); 

}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 NSLog(@"bbb");

}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 NSLog(@"bbb");

}

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@"ccc");

}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
NSLog(@"shouldAutorotateToInterfaceOrientation");

}

but no one was called... Can anyone help me in working out why the custom alert view isn't rotating like i want ?

UPDATE : i was implement the viewWillAppear method like this

-(void)viewWillAppear:(BOOL)animated {

UIInterfaceOrientation toOrientation = self.interfaceOrientation;
if(toOrientation == UIInterfaceOrientationPortrait){
    CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 180 / 180.0f);
    NSLog(@"vwa : portrait upside down");

    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];

    //[self.view setTransform:affine];
    self.view.center = CGPointMake(160, 240);
    NSLog(@"affine : %f", affine);

}else if(toOrientation == UIInterfaceOrientationPortraitUpsideDown){
    CGAffineTransform affine = CGAffineTransformMakeRotation (0.0);

    NSLog(@"vwa : Portrait ");

    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];
    self.view.center = CGPointMake(160, 240);
    NSLog(@"affine : %f", affine);
}else if(toOrientation == UIInterfaceOrientationLandscapeLeft){
    CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 270 / 180.0f);

    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];
    self.view.center = CGPointMake(160, 240);

    NSLog(@"vwa : landscpae left");

    NSLog(@"affine : %f", affine);
}else{
    CGAffineTransform affine = CGAffineTransformMakeRotation ( M_PI * 90 / 180.0f);
    [self.alertView setTransform:affine];
    [self.backgroundView setTransform:affine];
    self.view.center = CGPointMake(160, 240);

    NSLog(@"vwa : landscape right");
    NSLog(@"affine : %f", affine);
}

}

but the condition just fulfilled at the first time launching the app, after that, there're no condition and statement called even i rotate the device many times

R. Dewi
  • 4,141
  • 9
  • 41
  • 66

2 Answers2

1

It's DONE... see About the orientation of iPhone to find the answer :)

Community
  • 1
  • 1
R. Dewi
  • 4,141
  • 9
  • 41
  • 66
0

UIView cannot accept the delegate messages of UIViewController. So you should register as an observer to receive the UIDeviceOrientationDidChangeNotification notification.

AechoLiu
  • 17,522
  • 9
  • 100
  • 118
  • i'm sorry..i dont understand how to register as an observer, can you describe it? – R. Dewi Nov 26 '10 at 08:32
  • toro...did you mean register as an observer like the answer on this http://stackoverflow.com/questions/3829756/about-the-orientation-of-iphone ?? it's yours right? :) – R. Dewi Nov 26 '10 at 08:45