6

I am using a UIImageView-based animation to show a custom activity indicator. The following code is responsible for setting this :

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

Here is a gist with the UIImageView+Animation category.

Whenever I am starting a web request, I am starting the activity indicator, and whenever the request is done, I am stopping it by setting the titleView property to nil.

The result is this:

OK

The request method is also called into the -viewDidAppear: method of the view controller.

However, whenever the animation starts during a transition, it seems like the position of the UIImageView is wrong.

The following result is showing the problem:

Please notice how the activity indicator is showing on top of the "Groups" button.

KO

Where is this problem coming from? How can I solve it?

2 Answers 2

0

I think the problem is that although your setting your titleView to nil, you do not remove the loader from the view, so it's frame goes to (0,0) position.

Try the following:

+ (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;
}

And whenever setting the

titleView = nil

Also do

[[self.navigationController.view viewWithTag:999] removeFromSuperView];
3
  • I tried and it doesn't seem to be that. The problem occurs when the loader is added.
    – thegameg
    Apr 12, 2015 at 19:59
  • I've edited my answer to remove to view from the navigation controller. Does it help?
    – Asaf
    Apr 12, 2015 at 20:24
  • No, it didn't change anything. Thanks anyway.
    – thegameg
    Apr 12, 2015 at 22:28
0

This question is really nice demo of the issue, and the answers are here: Stackoverflow title moves while push/pop of viewcontroller

Long story short:

  1. Use UIView with .autoresizingMask = UIViewAutoresizingFlexibleTopMargin
  2. Don't do it in "viewWillAppear:" (do in viewDidLoad / update in DidAppear or later )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.