Ios 图像视图在应用变换时更改位置?
我有一个IPhone应用程序,我想在不改变图像视图位置的情况下将图像视图转换为两倍大小(即中心不需要改变),我就是这样做的Ios 图像视图在应用变换时更改位置?,ios,iphone,ipad,uiimageview,uiviewanimation,Ios,Iphone,Ipad,Uiimageview,Uiviewanimation,我有一个IPhone应用程序,我想在不改变图像视图位置的情况下将图像视图转换为两倍大小(即中心不需要改变),我就是这样做的 CGAffineTransform firstTransform = bg.transform; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.5]; bg.transform = CGAffineTransformScale(bg.transform,2,2)
CGAffineTransform firstTransform = bg.transform;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.5];
bg.transform = CGAffineTransformScale(bg.transform,2,2);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.5];
bg.transform = firstTransform;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
但当转变立场时,它的地位会改变
现在我这样做是为了不改变图像视图的位置。我希望图像视图在点击时通过这样的动画转换为两倍大小
CGAffineTransform firstTransform = bg.transform;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.5];
bg.transform = CGAffineTransformScale(bg.transform,2,2);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.5];
bg.transform = firstTransform;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
有人能告诉我这一点吗?请确保将锚定点设置为中心,同时记住在设置锚定点时,该值必须介于0和1之间:0表示左侧/顶部,1表示右侧/底部。因此,要将锚点设置为中间,请在X轴和Y轴上将其设置为0.5:
[itemName.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
然后,当您缩放对象时,它应该围绕中心点向上缩放
我还建议使用。代码将变得更加简单:
[UIView animateWithDuration:1.0f animations:^{
[bg setTransform:CGAffineTransformScale(bg.transform, 2.0, 2.0)];
} completion ^{
[UIView animateWithDuration:1.0f animations:^{
[bg setTransform:CGAffineTransformScale(bg.transform, 0.5, 0.5)];
];
}];
希望这能帮助你达到预期的效果 确保您没有使用自动布局。要禁用该选项,请单击右侧面板中的第一个选项卡,取消选中Interface Builder文档下的“使用自动布局”。附加屏幕截图以获取帮助
使用[uiview animateWithduration:completion]块使用嵌套动画。在一个动画完成后,将执行完成块。在那里添加下一个动画。在他的问题中:“(即,不需要更改中心)”-此外,提供的链接显示了一个圆,因此我假设中心将是锚定点