// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
NSLog(@"interfaceOrientation");
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown);
// take out the ones you DON'T want to be available
}
// if you want to change things based on orientation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
{
switch (interfaceOrientation)
{
case UIInterfaceOrientationPortrait:
{
//changes for Portait
NSLog(@"Portait");
[imgView setFrame:CGRectMake(0,0,768,1024)];
[imgView setImage:[UIImage imageNamed:@"1.jpg"]];
}
break;
case UIInterfaceOrientationPortraitUpsideDown:
{
//changes for PortaitUpsideDown
NSLog(@"PortaitUpsideDown");
[imgView setFrame:CGRectMake(0,0,768,1024)];
[imgView setImage:[UIImage imageNamed:@"1.jpg"]];
}
break;
case UIInterfaceOrientationLandscapeRight:
{
//changes for LandscapeRight
NSLog(@"LandscapeRight");
[imgView setFrame:CGRectMake(0,0,1024,768)];
[imgView setImage:[UIImage imageNamed:@"2.jpg"]];
}
break;
case UIInterfaceOrientationLandscapeLeft:
{
//changes for LandscapeRight
NSLog(@"LandscapeRight");
[imgView setFrame:CGRectMake(0,0,1024,768)];
[imgView setImage:[UIImage imageNamed:@"2.jpg"]];
}
break;
}
}
其iPad實例與iPhone相同。 將768和1024更改爲iPhone大小。 – 2011-04-08 13:28:32