我在InterfaceBuilder的UIViewController中有一個自定義的UIView videoView
。更改方向時定位UIview
當我加載它時,它看起來很好,但是當我把它說成「從肖像風景」它不會去座標告訴它的地方。然後當我把它回來時,它又錯了。
我有以下代碼:
-(void)viewWillAppear:(BOOL)animated
{
[self processRotation:self.interfaceOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)processRotation:(UIInterfaceOrientation)_interfaceOrientation
{
if (_interfaceOrientation == UIInterfaceOrientationLandscapeLeft || _interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
videoView.frame = CGRectMake(20.0f, 77.0f, 984.0f, 595.0f);
}
else if (_interfaceOrientation == UIInterfaceOrientationPortrait || _interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
videoView.frame = CGRectMake(20.0f, 297.0f, 728.0f, 453.0f);
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self processRotation:toInterfaceOrientation];
}
嗨代代,我可以推薦一個最近的帖子,它會幫助你的查詢:http://stackoverflow.com/questions/6580052/how-to-change-view-of-the-viewcontroller-when-改變方向在iPhone/6580111#6580111 – Luke