Ios 将UIImageView添加为子视图
我正在尝试创建具有特定图像约束的动画UIImageView 我希望UIImageView的动画大小为141x262,而不是整个屏幕。目前我有以下代码:Ios 将UIImageView添加为子视图,ios,imageview,subview,Ios,Imageview,Subview,我正在尝试创建具有特定图像约束的动画UIImageView 我希望UIImageView的动画大小为141x262,而不是整个屏幕。目前我有以下代码: CJ = [[UIImageView alloc] initWithFrame:self.view.frame]; CJ.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"CJ_1.png"],
CJ = [[UIImageView alloc] initWithFrame:self.view.frame];
CJ.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"CJ_1.png"],
[UIImage imageNamed:@"CJ_2.png"],
[UIImage imageNamed:@"CJ_3.png"], nil];
CJ.animationDuration = 1;
CJ.animationRepeatCount = 0;
[CJ startAnimating];
[self.view addSubview:CJ];
任何和所有的帮助将不胜感激 如果希望视图的大小不同,请将其边框设置为该大小:
CJ = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 141, 162)];
如果图像较大,您可能还希望在视图上设置contentMode。例如:
CJ.contentMode = UIViewContentModeScaleAspectFit;
你也在使用interface builder吗?是的,我在使用interface builder。不,它仍然占据整个屏幕。我添加了另一个建议不是图像太大,而是Xcode在拉伸图像(我只希望它是它的大小)。Xcode:我想要的:您可能需要使用不同的内容模式(
UIViewContentModeCenter
?)或在分配动画图像后设置帧(CG.frame=CGRectMake(0,0,141162)
)。但是,如果您使用的是Interface Builder,我不确定您为什么要在代码中创建此视图。我首先尝试了Interface Builder,但运气不好。现在我在代码中尝试它,我仍然没有运气。