我有一个包含图像集合的 View 。如果单击图像,那么我会在同一屏幕上全屏显示它。当手机旋转时,我希望它仅在图像全屏时自动旋转,否则不自动旋转。我有 isZoomedIn
当图像全屏显示时为 true,否则为 false。
我已经实现了方法shouldAutorotate
。如果放大则返回 Yes,否则返回 No,但即使正确设置了 isZoomedIn
,它也不起作用。
最佳答案
我创建了一个演示,它有一个按钮,可以在同一屏幕上弹出一个新 View ,类似于您在单击时选择的图像。
-(IBAction)buttonClicked:(id)sender //Called when button tapped to pop-up a new view.
{
flag = YES; //Flag check for rotating new view ,i.e., YES.
newView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width-10, self.view.frame.size.height-10)];
[newView setBackgroundColor:[UIColor blueColor]];
closeNewViewBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 30, 100, 50)];
[closeNewViewBtn addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchUpInside];
[closeNewViewBtn setTitle:@"Remove View" forState:UIControlStateNormal];
[closeNewViewBtn setBackgroundColor:[UIColor redColor]];
[newView addSubview:closeNewViewBtn];
[self.view addSubview:newView];
}
-(void)removeView //Called to remove view or in your case change it for removing the image or what ever you doing.
{
flag = NO;
[newView removeFromSuperview];
}
-(BOOL)shouldAutorotate //Rotation check
{
if(flag)
return YES; //Will rotate when new view is present.
else
return NO; //Will not rotate when new view is not present.
}
这将满足您的需求。
关于ios - 具有不同自动旋转选项的屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24011259/