简体   繁体   中英

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.

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];

}

self.clipsToBounds = NO; is the solution

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

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

where self represents the UIImageView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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