在iOS中使用循环设置背景动画
在我的视图上使用此代码制作动画背景 实际上有3张图片,分别命名为在iOS中使用循环设置背景动画,ios,objective-c,ipad,view,background,Ios,Objective C,Ipad,View,Background,在我的视图上使用此代码制作动画背景 实际上有3张图片,分别命名为background\u screen-1.png,background\u screen-2.png,background\u screen-3.png 在我的viewDidLoad中,我使用以下代码: - (void)viewDidLoad { self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage animatedImageNamed:@"
background\u screen-1.png
,background\u screen-2.png
,background\u screen-3.png
在我的viewDidLoad
中,我使用以下代码:
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage animatedImageNamed:@"background_screen-" duration:1.0f]];
}
仅显示
background\u screen-1.png
。如何在我的3张图片之间获得一个循环以获得动画背景?拍摄一个UIImageView
,您可以像下面这样做,因为UIImageView
具有内置的动画制作方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Load images
NSArray *imageNames = @[@"win_1.png", @"win_2.png", @"win_3.png", @"win_4.png",
@"win_5.png", @"win_6.png", @"win_7.png", @"win_8.png",
@"win_9.png", @"win_10.png", @"win_11.png", @"win_12.png",
@"win_13.png", @"win_14.png", @"win_15.png", @"win_16.png"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
}
-(void)viewDidLoad
{
[超级视图下载];
//加载图像
NSArray*imageNames=@[@“win_1.png”、@“win_2.png”、@“win_3.png”、@“win_4.png”,
@“win_5.png”、“win_6.png”、“win_7.png”、“win_8.png”,
@“win_9.png”、@“win_10.png”、@“win_11.png”、@“win_12.png”,
@“win_13.png”、“win_14.png”、“win_15.png”、“win_16.png”];
NSMutableArray*图像=[[NSMutableArray alloc]init];
对于(int i=0;i
colorWithPatternImage
创建静态颜色,而不是随时间变化的颜色
您可以使用UIImageView
作为ViewController的背景。只需将动画图像用作该视图的图像