我如何根据我的动画图像更改 UIImageView 的大小,因为它们比初始 UIImage 大
这是我的代码,我正在尝试拖放一张卡片,该卡片将在触摸开始时产生动画效果,但动画图像大于触摸开始之前的初始卡片图像。
我如何更改 UIImageView 以适应 animateImages 尺寸?
cardAnimationArray 是一个包含 19 个图像 xxx1.png、xxx2.png... 的数组,它们具有不同的大小。
cardMovedImage 是 19 个图像系列中的最后一个图像。 先感谢您!!
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:self.superview];
self.center = pt;
self.animationImages = [NSArray arrayWithArray:cardAnimationArray];
[cardAnimationArray release];
[self setAnimationRepeatCount:1];
self.animationDuration= 1;
[self startAnimating];
self.image = [UIImage imageNamed:cardMovedImageName];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:self.superview];
CGRect frame = [self frame];
frame.origin.x += pt.x - self.center.x;
frame.origin.y += pt.y - self.center.y;
[self setFrame: frame];
}
This is my code, i'm trying to drag and drop a card which will animate on touchesBegan, but the animationImages are larger than the initial card image before touches begin.
How can i change the UIImageView to accomdate the animateImages sizes?
cardAnimationArray is an array with 19 images xxx1.png, xxx2.png... which have various sizes.
cardMovedImage is the last image in the series of 19 images.
Thank you in advance!!
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:self.superview];
self.center = pt;
self.animationImages = [NSArray arrayWithArray:cardAnimationArray];
[cardAnimationArray release];
[self setAnimationRepeatCount:1];
self.animationDuration= 1;
[self startAnimating];
self.image = [UIImage imageNamed:cardMovedImageName];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:self.superview];
CGRect frame = [self frame];
frame.origin.x += pt.x - self.center.x;
frame.origin.y += pt.y - self.center.y;
[self setFrame: frame];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
self.clipsToBounds = NO;是解决方案
self.clipsToBounds = NO; is the solution
将缩放模式设置为“居中”
Set the scale mode to "Center"
哈哈,其实有一个简单的解决办法;
只需设置 self.clipsToBounds = NO;
其中 self 代表 UIImageView
Haha, there is actually a simple solution;
just set self.clipsToBounds = NO;
where self represents the UIImageView