【发布时间】:2017-07-10 17:33:57
【问题描述】:
我正在尝试每秒更改一次 UIImageView。
更改可以是以下两种之一: - 回转 - 位置变化
我正在使用以下内容:
这是初始化代码:
+(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];
}
}
}
由于某种原因,一旦中心发生变化并应用了旋转,图像就会变大!
有人知道为什么以及我能做什么吗?
谢谢!
【问题讨论】:
-
不应该是
locationView.transform = transform;吗? -
我无法使用您提供的代码重现您的问题。你能提供更多细节吗?
-
尝试在循环中运行此代码,在每个奇数情况下更改中心并在每个偶数情况下更改旋转。中心变化导致我的图像增长.. 我知道旋转本身可以改变帧大小,我无法理解的是为什么图像大小会随着我每次重新中心而改变
-
我无法重现您的体验。旋转本身不能改变帧大小。转换使
frame返回的值无效。我的预感是自动调整大小行为或布局约束相互作用正在发生。没有可重现的例子,我无能为力。 -
我有一个 xib 文件,上面只有一个 imageview。图像视图具有以下约束: [ 0 from top 0 from left 0 from right 0 from bottom ] 问题是,一旦我设置了一个新的中心,图像视图就会由于某种原因被炸毁。我知道这不是很多工作有,但我不确定我还能提供什么..
标签: ios objective-c uiview