我使用以下代码将图像置于视图中心
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];
问题是我运行此代码时没有显示imaeview。我怎样才能解决这个问题?
答案 0 :(得分:1)
您好,这是代码
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];