gpt4 book ai didi

ios - Uiimageview 动画没有显示

转载 作者:行者123 更新时间:2023-11-29 00:45:46 24 4
gpt4 key购买 nike

我使用以下代码将图像置于 View 中居中

 UIImage* img1 = [UIImage imageNamed:@"1.gif"];
UIImage* img2 = [UIImage imageNamed:@"2.gif"];
UIImage* img3 = [UIImage imageNamed:@"3.gif"];
UIImage* img4 = [UIImage imageNamed:@"4.gif"];



UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, self.view.frame.size.height/4, 170, 170)];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(65, 40, loadingView.bounds.size.width, loadingView.bounds.size.height)];
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
loadingView.clipsToBounds = YES;
loadingView.layer.cornerRadius = 10.0;
loadingView.center = self.view.center;
imgView.backgroundColor = [UIColor clearColor];
imgView.center = loadingView.center;
imgView.animationImages = @[img1, img2, img3, img4];
imgView.animationDuration = 1.0*1.0;
[loadingView addSubview: imgView];
[self.view addSubview:loadingView];
[imgView startAnimating];
  1. 我最初定义了四个 uiimage
  2. 我已经定义了加载 View ,并将其置于屏幕中心
  3. 我定义了一个 ImageView ,并将其置于加载 View 的中心。
  4. 我已将imageview添加为loadingView的 subview ,并将加载 View 添加到 View 中。然后我为imageview设置动画

问题是当我运行这段代码时,imaeview 没有显示。我怎样才能解决这个问题?

最佳答案

你好这是代码

UIImage* img1 = [UIImage imageNamed:@"1.gif"];
UIImage* img2 = [UIImage imageNamed:@"2.gif"];

UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, self.view.frame.size.height/4, 170, 170)];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 170, 170)];
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
loadingView.clipsToBounds = YES;
loadingView.layer.cornerRadius = 10.0;
loadingView.center = self.view.center;
imgView.backgroundColor = [UIColor clearColor];
imgView.animationImages = @[img1, img2];
imgView.animationDuration = 1.0*1.0;
[loadingView addSubview: imgView];
[imgView startAnimating];
[self.view addSubview:loadingView];

关于ios - Uiimageview 动画没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38604975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com