【发布时间】:2016-07-27 06:08:35
【问题描述】:
我使用以下代码在视图中将图像居中
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];
- 我最初定义了四个 uiimages
- 我已经定义了加载视图并将其置于屏幕的中心
- 我已经定义了一个 imageview 并且我已经将它置于加载视图的中心。
- 我已将 imageview 添加为 loadingView 的子视图,并将加载视图添加到视图中。然后我为 imageview 设置动画
问题是当我运行此代码时没有显示 imaeview。我怎样才能解决这个问题?
【问题讨论】:
-
我认为你的
frame不正确,因为其他代码是正确的,由于错误的框架它不可见,尝试调试。 -
imgView.center = loadingView.center;不正确,要使用此代码进行正确的动画制作,您需要将图像分解为单独的 png/jpeg 文件。
-
使用SDWebImage设置gif图片
标签: ios objective-c uiview uiimageview