UINavigationItem titleView animation

I am using UIImageView based animation to show a user activity indicator. To set this parameter, the following code answers:

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

Here's the gist in the UIImageView + Animation category.

When I start a web request, I start the activity indicator, and whenever the request is executed, I stop it by setting the titleView property to nil .

The result is the following:

Ok

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

However, whenever the animation starts during the transition, it seems that the position of the UIImageView is incorrect.

The following result shows the problem:

Notice that the activity indicator appears at the top of the Groups button.

Ko

Where does this problem come from? How can I solve it?

+6
source share
2 answers

I think the problem is that although you set your title to zero, you are not removing the loader from the view, so it 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 you install

 titleView = nil 

Also do

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

This question is really a nice demonstration of the problem, and the answers are here: fooobar.com/questions/228455 / ...

Shortly speaking:

  • Use UIView with .autoresizingMask = UIViewAutoresizingFlexibleTopMargin
  • Do not do this in "viewWillAppear:" (do in viewDidLoad / update in DidAppear or later)
0
source

Source: https://habr.com/ru/post/985028/


All Articles