综合技术

UIActivityIndicatorView not animated

微信扫一扫,分享到朋友圈

UIActivityIndicatorView not animated
0

I keep getting the UIActivityIndicatorView into view but not animating.

I’m not doing extensive processing I just add my class as a subview to the view of an UITableViewController and do nothing else.

Here is the class I use to layout my UIActivityIndicatorView:

#import "UIXLoaderView.h"
#import <QuartzCore/QuartzCore.h>

@interface UIXLoaderView () {
@private
    UIActivityIndicatorView *activityIndicatorView;
}
@end

@implementation UIXLoaderView

- (id)init {
    self = [super init];
    if (self) {
        // Measure Loading string
        NSString *loadingText = NSLocalizedString(@"Loading...", @"Loading...");
        CGSize textSize = [loadingText sizeWithFont:[UIFont systemFontOfSize:14] forWidth:280 lineBreakMode:UILineBreakModeTailTruncation];

        // Create activity gauge
        activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

        // now set our frame
        if (activityIndicatorView.frame.size.width > textSize.width) {
            [self setFrame:CGRectMake(0, 0, activityIndicatorView.frame.size.width + 20, activityIndicatorView.frame.size.height + textSize.height + 30)];
        } else {
            [self setFrame:CGRectMake(0, 0, textSize.width + 20, activityIndicatorView.frame.size.height + textSize.height + 30)];
        }

        // Add the activity gauge into the view
        [activityIndicatorView setFrame:CGRectMake(((self.frame.size.width - activityIndicatorView.frame.size.width) / 2) , 10, activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.width)];
        [self addSubview:activityIndicatorView];

        // Create and add the label
        UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(((self.frame.size.width - textSize.width) / 2), activityIndicatorView.frame.origin.y + activityIndicatorView.frame.size.height + 10, textSize.width, textSize.height)];
        [loadingLabel setText:loadingText];
        [loadingLabel setFont:[UIFont systemFontOfSize:14]];
        [loadingLabel setLineBreakMode:UILineBreakModeTailTruncation];
        [loadingLabel setBackgroundColor:[UIColor clearColor]];
        [loadingLabel setTextColor:[UIColor whiteColor]];
        [self addSubview:loadingLabel];

        // rounded corners
        [[self layer] setCornerRadius:9.0];
        //[[self layer] setBorderWidth:1.0];
        //[[self layer] setBorderColor:[[UIColor blackColor] CGColor]];

        // back color
        [self setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f]];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)removeFromSuperview {
    // Stop animating
    [activityIndicatorView stopAnimating];

    // Call super
    [super removeFromSuperview];
}

- (void)didMoveToSuperview {
    // Move to center
    [self setCenter:[[self superview] center]]; 

    // Call super
    [super didMoveToSuperview];

    // Animate
    [activityIndicatorView setHidden:NO];
    [activityIndicatorView startAnimating];
}

@end

The header file is:

#import <UIKit/UIKit.h>

@interface UIXLoaderView : UIView

@end

Inside a UITableViewController I just call it in the following way:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // If no data start loading animation
    if (!self->data) {
        // Show the loading view
        loaderView = [[UIXLoaderView alloc] init];
        [self.view addSubview:loaderView];
    }

}

The starngest thing here is the animation will start if I tap and move the tableView, but it won’t animate once the control is loaded… and I can’t fugure out what is happening here. Any clues?

阅读原文...

微信扫一扫,分享到朋友圈

UIActivityIndicatorView not animated
0
Hello, buddy!

谷歌、微软、阿里云……六大云厂商区块链服务哪家强?

上一篇

前端实习面试的一些建议

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

UIActivityIndicatorView not animated

长按储存图像,分享给朋友