Ios UIImageView旋转+;中心改变会导致图像爆炸
我试图每秒钟做一次UIImageView更改 更改可以有以下两种情况之一: -轮换 -位置变更 我正在使用以下工具: 这是初始化代码:Ios UIImageView旋转+;中心改变会导致图像爆炸,ios,objective-c,uiview,Ios,Objective C,Uiview,我试图每秒钟做一次UIImageView更改 更改可以有以下两种情况之一: -轮换 -位置变更 我正在使用以下工具: 这是初始化代码: +(instancetype)newWithFrame:(CGRect)frame { MySateliteView *v = [[[NSBundle mainBundle] loadNibNamed:@"Satelite" owner:self options:nil] objectAtIndex:0]; v.frame = frame;
+(instancetype)newWithFrame:(CGRect)frame {
MySateliteView *v = [[[NSBundle mainBundle] loadNibNamed:@"Satelite" owner:self options:nil] objectAtIndex:0];
v.frame = frame;
v.lastLocation = [SateliteCoordinate new];
return v;
}
这是视图的完整代码:
-(void)createSateliteViewFromLocation:(SateliteLocation *)location {
CGPoint center = [self createPointFromLocation:location];
MySateliteView *locationView;
for (MySateliteView *v in _satelites) {
if (v.tag == location.sateliteNumber.integerValue) {
locationView = v;
break;
}
}
if (!locationView) {
locationView = [MySateliteView newWithFrame:CGRectMake(center.x - 15, center.y - 15, 30, 30)];
locationView rotate:location.coordinates.degree];
locationView.tag = location.sateliteNumber.integerValue;
[_satelites addObject:locationView];
[UIView animateWithDuration:0.7 animations:^{
[self addSubview:locationView];
}];
} else {
if ([locationView needsNewCenter:location.coordinates]) {
[UIView animateWithDuration:0.2 animations:^{
locationView.bounds = CGRectMake(0, 0, 30, 30);
locationView.center = center;
locationView.superview.clipsToBounds = YES;
}];
}
if ([locationView needsRotate:location.coordinates]) {
[locationView rotate:location.coordinates.degree];
}
}
}
由于某些原因,一旦中心改变并应用了旋转,图像就会变大
有人知道为什么,我能做什么吗
塔克斯 帧越来越大,因为您在视图中有约束,并且您正在手动处理中心。您不应该以这种方式混合自动布局和手动布局。我建议:
layoutSubviews
和drawRect:
来删除约束并手动执行所有视图布局,同时继续保留现有代码updateConstraints
方法,以确保适当提供约束[UIView animateWithDuration: .7, animations: ^{
self.constraint1.constant = 23;
[NSLayoutConstraint deactivateConstraints: @[self.constraint2]];
[self layoutIfNeeded];
}];
它不应该是
locationView.transform=transform代码>?我无法用您提供的代码重现您的问题。你能提供更多的细节吗?试着在一个循环中运行这个代码,在这个循环中,你每奇数改变一次中心,每偶数改变一次旋转。中心更改导致我的图像增长。。我知道旋转本身可以改变帧的大小,但我不明白的是,为什么图像的大小会随着每次重新居中而改变,我无法重现你所经历的。旋转本身无法更改帧大小。转换使frame
返回的值无效。我的直觉是,要么存在自动调整大小的行为,要么存在布局约束的相互作用。如果没有一个可复制的示例,我就无能为力。我有一个xib文件,上面只有一个imageview。imageview有以下限制:[0从顶部开始0从左侧开始0从右侧开始0从底部开始]问题是,一旦我设置了一个新的中心,图像视图就会由于某种原因被吹走。。我知道这不是很多工作,但我不确定我还能提供什么。。