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

时间:2014-06-03 09:12:47

标签: ios iphone objective-c ios7

我有一组图像的视图。如果单击图像,则在同一屏幕上显示全屏。当手机旋转时,我希望它仅在图像全屏时自动旋转,否则不需要。我有isZoomedIn,当图像全屏时为true,否则为false。

我已经实现了方法shouldAutorotate。如果它是放大的,则返回是,否则为否,但即使isZoomedIn被设置为核心,它也不起作用。

1 个答案:

答案 0 :(得分:1)

我创建了一个演示,其中有一个按钮可以在同一个屏幕上弹出一个新视图,类似于点击时的图像选择。

-(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.
}

这将满足您的需求。