在我的应用程序中,我有一个按钮和两个视图,当我点击按钮时,我从超级视图中删除了第一个视图,并将超级视图上的第二个视图添加为子视图。但问题是,当我将设备方向从纵向更改为横向,然后点击按钮时,它将以纵向视图而不是横向模式显示视图,反之亦然。这是我正在使用的代码。
- (void)showFiles {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.25];
[UIView setAnimationTransition:([songTableView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:toggleButton cache:YES];
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
[songTableView setFrame:CGRectMake(0.0f, 44.0f, 480.0f, 256.0f)];
}
else {
[songTableView setFrame:CGRectMake(0.0f, 44.0f, 320.0f, 416.0f)];
}
if ([songTableView superview]) {
[toggleButton setImage:[UIImage imageNamed:@"AudioPlayerAlbumInfo.png"] forState:UIControlStateNormal];
}
else {
[toggleButton setImage:albumArtImageView.image forState:UIControlStateNormal];
}
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:([songTableView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:self.view cache:YES];
if ([songTableView superview])
{
albumArtImageView.image = albumArtImage;
albumArtImageView.contentMode = UIViewContentModeScaleAspectFit;
albumArtImageView.clipsToBounds = YES;
[songTableView removeFromSuperview];
[gradientLayer removeFromSuperlayer];
[self.view addSubview:uppercontrollsView];
[self.view addSubview:lowercontrollsView];
}
else
{
[albumArtImageView setImage:[UIImage imageNamed:@"AudioPlayerTableBackground.png"]];
albumArtImageView.contentMode = UIViewContentModeScaleAspectFill;
albumArtImageView.clipsToBounds = YES;
[uppercontrollsView removeFromSuperview];
[lowercontrollsView removeFromSuperview];
[self.view addSubview:songTableView];
[songTableView reloadData];
}
[UIView commitAnimations];
}