【问题标题】:UINavigationItem titleView animationUINavigationItem 标题查看动画
【发布时间】:2015-04-12 18:52:31
【问题描述】:

我正在使用基于 UIImageView 的动画来显示自定义活动指示器。 以下代码负责设置:

+ (void)startLoadingActivity:(UIViewController *)vc {
    vc.parentViewController.navigationItem.titleView = [UIImageView imageViewWithPath:@"loading_" count:10 duration:1.3 frame:CGRectMake(0, 0, 22, 22)];
}

这是UIImageView+Animation 类别的要点。

每当我开始一个网络请求时,我都会启动活动指示器,而每当请求完成时,我都会通过将titleView 属性设置为nil 来停止它。

结果是这样的:

请求方法也被调用到视图控制器的-viewDidAppear:方法中。

但是,每当动画在过渡期间开始时,UIImageView 的位置似乎是错误的。

以下结果显示问题:

请注意活动指示器在“组”按钮顶部的显示方式。

这个问题是从哪里来的?我该如何解决?

【问题讨论】:

    标签: ios objective-c animation uiimageview titleview


    【解决方案1】:

    我认为问题在于,尽管您将 titleView 设置为 nil,但您并没有从视图中删除加载程序,因此它的框架转到 (0,0) 位置。

    尝试以下方法:

    + (void)startLoadingActivity:(UIViewController *)vc {
        UIImageView *imageView = [UIImageView imageViewWithPath:@"loading_" count:10 duration:1.3 frame:CGRectMake(0, 0, 22, 22)];
        imageView.tag = 999;
        vc.parentViewController.navigationItem.titleView = imageView;
    }
    

    而且无论何时设置

    titleView = nil
    

    也可以

    [[self.navigationController.view viewWithTag:999] removeFromSuperView];
    

    【讨论】:

    • 我试过了,好像不是这样。添加loader时出现问题。
    • 我已经编辑了我的答案以从导航控制器中删除以查看。有帮助吗?
    • 不,它没有改变任何东西。无论如何,谢谢。
    【解决方案2】:

    这个问题很好地演示了这个问题,答案在这里: Stackoverflow title moves while push/pop of viewcontroller

    长话短说:

    1. 将 UIView 与 .autoresizingMask = UIViewAutoresizingFlexibleTopMargin 一起使用
    2. 不要在“viewWillAppear:”中执行(在 viewDidLoad 中执行/在 DidAppear 或更高版本中更新)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2011-06-28
      相关资源
      最近更新 更多