我如何根据我的动画图像更改 UIImageView 的大小,因为它们比初始 UIImage 大

发布于 2024-08-15 15:06:34 字数 980 浏览 4 评论 0原文

这是我的代码,我正在尝试拖放一张卡片,该卡片将在触摸开始时产生动画效果,但动画图像大于触摸开始之前的初始卡片图像。

我如何更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最单纯的乌龟 2024-08-22 15:06:34

self.clipsToBounds = NO;是解决方案

self.clipsToBounds = NO; is the solution

心是晴朗的。 2024-08-22 15:06:34

将缩放模式设置为“居中”

Set the scale mode to "Center"

孤独陪着我 2024-08-22 15:06:34

哈哈,其实有一个简单的解决办法;
只需设置 self.clipsToBounds = NO;

其中 self 代表 UIImageView

Haha, there is actually a simple solution;
just set self.clipsToBounds = NO;

where self represents the UIImageView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文