ios - 具有不同自动旋转选项的屏幕

标签 ios iphone objective-c ios7

我有一个包含图像集合的 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/

相关文章:

ios - 文本字段键盘设置为数字键盘,但在选择时显示常规键盘

iphone - Xcode自动将对象转换为NSArray

ios - 禁用时保持 UIButton 当前状态

ios - 如何减少 WKInterfaceTable 中的行间距

iOS - 安排多个本地通知,UNCalendarNotificationTrigger

ios - iOS 的应用程序组织

iphone - 更改来自不同类的 UIButton alpha

iphone - 通过使用 2 个按钮操作调用相同 View 导致 segue 出错

ios - 在 iOS 应用程序中使用 C++ 库

ios - 使用自定义 linter 规则的 Objective C 静态分析?