【问题标题】:iPhone UIActionSheet auto-rotating not workingiPhone UIActionSheet 自动旋转不起作用
【发布时间】:2013-02-16 08:16:45
【问题描述】:

我读了很多关于这方面的文章。人们说当它的父级没有设置为自动旋转时它不会自动旋转。我尝试了一切,但没有运气。 我创建了一个基于视图的应用程序 (v4.2),并带有一个执行此操作的按钮:

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Other Button 1", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    [actionSheet showInView:self.view];

根控制器设置为自动旋转。 actionSheet 没有。请注意,当我旋转模拟器时,不会调用任何根控制器的方向方法。代表有问题吗?怎么了?

【问题讨论】:

  • 尝试使用showInTabbarshowFromBarButtonItemshowInView 有时候有点傻。
  • 不...相同,不旋转。
  • 你找到解决这个问题的方法了吗?我也面临同样的问题。

标签: iphone orientation rotation uiactionsheet autorotate


【解决方案1】:

好吧,这是我对这个问题的解决方案:

基本上我们做的是:

  1. 收听轮换事件。
  2. 监听点击事件。
  3. 关闭 actionSheet 并在旋转完成后再次显示它。 (我们需要稍等片刻才能完成。

例如:

@interface ViewController ()
{
    UIActionSheet *_sheet;
    BOOL _isClicked;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (IBAction)click:(id)sender
{
    _isClicked = YES;

    [self showActionSheet];
}

- (void)didRotate:(NSNotification *)note
{
    [_sheet dismissWithClickedButtonIndex:1 animated:YES];
    [self performSelector:@selector(showActionSheet) withObject:nil afterDelay:1.0];
}

- (void)showActionSheet
{
    if (!_isClicked) return;

    _sheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"new" otherButtonTitles:@"bla", nil];
    [_sheet showInView:self.view];
}

【讨论】:

  • 面朝上和面朝下的设备方向如何?
【解决方案2】:

我发现当我在从属视图(我使用导航控制器推送)的委托方法中呈现操作表时遇到了这个问题。问题是我的视图不是当前视图,从属视图仍在我试图显示操作表的位置。

通过稍微更改我的代码,以便委托方法记录与用户所需的交互,并将操作表呈现推迟到该视图的 viewDidAppear 方法,该表在逻辑界面动画中的适当时间出现,自动旋转问题就消失了。您可能想看看这是否对您有帮助。

换句话说,流程变成了:

  • 从属视图调用委托方法来报告用户在离开时所做的选择。
  • 父视图记录此信息以备后用。
  • 导航控制器被告知弹出从属视图。
  • 父视图的 viewDidLoad: 方法检测到委托方法中的注释。
  • 提交了行动表;旋转现在是正确的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2011-05-11
    相关资源
    最近更新 更多