简体   繁体   English

我如何根据我的animationImages更改UIImageView的大小,因为它们大于初始UIImage

[英]how do i change the size of UIImageView according to my animationImages as they are bigger than initial UIImage

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. 这是我的代码,我试图拖放将在touchesBegan上动画的卡片,但是animationImages大于触摸开始之前的初始卡片图像。

How can i change the UIImageView to accomdate the animateImages sizes? 如何更改UIImageView以适应animateImages大小?

cardAnimationArray is an array with 19 images xxx1.png, xxx2.png... which have various sizes. cardAnimationArray是一个数组,其中包含19个图像xxx1.png,xxx2.png ...,它们的大小各不相同。

cardMovedImage is the last image in the series of 19 images. cardMovedImage是19张图像系列中的最后一张图像。 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];

}

self.clipsToBounds = NO; self.clipsToBounds = NO; is the solution 是解决方案

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

Haha, there is actually a simple solution; 哈哈,实际上有一个简单的解决方案。 just set self.clipsToBounds = NO; 只需设置self.clipsToBounds = NO;

where self represents the UIImageView 其中self代表UIImageView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM