I am trying to create a custom view which saves all the UIImage's in an array and then assign this array to animationImages property of UIImageView.
But the problem is this works fine if I do this inside the UIViewController where I want this however when I am trying to create this through a custom UIView its not displaying anything.
Here's my code:
@interface IndicatorView : UIView
@property(nonatomic, strong) UIImageView * indicatorView;
-(void)createIndicator;
-(void)startAnimating;
-(void)stopAnimating;
@end
#import "ConfIndicatorView.h"
@implementation ConfIndicatorView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self createIndicator];
}
return self;
}
-(void)createIndicator
{
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"spinner-1.png"],
[UIImage imageNamed:@"spinner-2.png"],
[UIImage imageNamed:@"spinner-3.png"],
nil];
_indicatorView = [[UIImageView alloc] initWithFrame:self.frame];
_indicatorView.animationImages = imageArray;
_indicatorView.animationDuration = 1.0f;
_indicatorView.contentMode = UIViewContentModeCenter;
[self addSubview:_indicatorView];
[_indicatorView startAnimating];// Just added this to see if it works but still not
}
-(void)startAnimating
{
[_indicatorView startAnimating];
}
-(void)stopAnimating
{
[_indicatorView stopAnimating];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
And I am using this as:
_spinner = [[IndicatorView alloc]initWithFrame:CGRectMake(160, 240, 80, 80)];
[self.view addSubview:_spinner];
[_spinner startAnimating];
You should use bounds
because you are doing it relative to the inner rect.
_indicatorView = [[UIImageView alloc] initWithFrame:self.frame];
change to
_indicatorView = [[UIImageView alloc] initWithFrame:self.bounds];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.