Objective c 如何在添加到UIView时显示UIImageview动画
我试图创建一个自定义视图,将所有UIImage保存在一个数组中,然后将此数组指定给UIImageView的animationImages属性 但问题是,如果我在UIViewController中执行此操作(我希望在其中执行此操作),则此操作可以正常工作。但是,当我尝试通过自定义UIView创建此操作时,它不会显示任何内容 这是我的密码:Objective c 如何在添加到UIView时显示UIImageview动画,objective-c,xcode,uiimageview,Objective C,Xcode,Uiimageview,我试图创建一个自定义视图,将所有UIImage保存在一个数组中,然后将此数组指定给UIImageView的animationImages属性 但问题是,如果我在UIViewController中执行此操作(我希望在其中执行此操作),则此操作可以正常工作。但是,当我尝试通过自定义UIView创建此操作时,它不会显示任何内容 这是我的密码: @interface IndicatorView : UIView @property(nonatomic, strong) UIImageView * in
@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
我用它来表示:
_spinner = [[IndicatorView alloc]initWithFrame:CGRectMake(160, 240, 80, 80)];
[self.view addSubview:_spinner];
[_spinner startAnimating];
您应该使用
bounds
,因为这样做是相对于内部rect的。\u indicatorView=[[UIImageView alloc]initWithFrame:self.frame]代码>
更改为
\u indicatorView=[[UIImageView alloc]initWithFrame:self.bounds]代码>