How to implement a loading animation when navigating in a iPhone app?

前端 未结 7 1915
情歌与酒
情歌与酒 2021-02-04 18:41

It seems like a pretty simple problem, but I have been unable to find any good answers.

What I\'m trying to do is to make some sort of animation while some function is l

7条回答
  •  我在风中等你
    2021-02-04 19:01

    Your issue will be that the activity indicator will not be displayed because it will only be shown on the next pass through the run loop - by which time you will have done everything you need to!

    The very very very easiest way of doing this is to move your code to call the next view into its own method then (having built a UIActivityIndicator as per other posts here) do

    [self.myactivityindicator startAnimating];
    [self performSelector:@selector(myCodeToCallTheView) withObject:nil afterDelay:0];
    

    this gives just enough of a chance for the indicator to be drawn before running your code to draw the view. Of course once your new view appears it will overwrite the selector.

提交回复
热议问题