I've got several images within my view. On rotation my images are being placed properly by means of a CGAffineTransformTranslate & Rotate.
However when I launch in PortraitUpsidedown a translation takes place which I defined wihin the
"-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrienta开发者_C百科tion duration:(NSTimeInterval)duration { " method.
This translation only has to take place on a orientation change with the device. How can I make sure that this translation doesn't happen on Launch?
EDIT:
Still got problems after your tip with implementing the viewWillAppear method.
Here is some code of my project.
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
image1.transform = CGAffineTransformTranslate( image1.transform, -65.0, 255.0);
image2.transform = CGAffineTransformTranslate( image2.transform, -65.0, 255.0);
}
else {
image1.transform = CGAffineTransformIdentity;
image2.transform = CGAffineTransformIdentity;
}
}
-(void) viewWillAppear:(BOOL)isRotated{
isRotated = FALSE;
}
But how do I implement the piece of code where I define
isRotated = TRUE;
Thanks for your help !
Use the shouldAutorotateToInterfaceOrientation
delegate method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
Set a BOOL
variable. Make it YES
when the interface is what we required to use CGAffineTransformTranslate
& rotate, or call the method from there to translate:
like:
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
// do something
精彩评论