So the below code moves the self.nowGamePiece to the center of the board, but it doesn't not change the size to 500 x 500. In fact, no matter what those values (width and height in CGRectMake) are, size doesn't change in this animation.
Why? self.nowGamePiece should also change its size to 500x 500 too!
//self.nowGamePiece is a UIView
[UIView animateWithDuration:7 animations:^{
self.nowGamePiece.frame = CGRectMake(self.gameBoardImageView.center.x,self.gameBoardImageView.center.y, 500, 500);
//doing below only moves the self.nowGamePiece too. Size doesn't change
//self.nowGamePiece.frame = CGRectMake(100, 100, 500, 500);
} completion:^(BOOL finished){
return;
}];
Try setting the autoResizingMask property of your view. I suspect your image is a subview of your nowGamePiece view, and it's just not resizing the image when the frame of the superview gets changed.
self.nowGamePiece.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.nowGamePiece.autoresizesSubviews = YES;
I think this method may be bugged. I solved it using transform instead.
[UIView animateWithDuration:7 animations:^{
self.nowGamePiece.transform =CGAffineTransformMakeScale(7.0, 7.0);
self.nowGamePiece.center = CGPointMake(self.gameBoardImageView.center.x, self.gameBoardImageView.center.y);
} completion:^(BOOL finished){
return;
}];
Try this instead:
//self.nowGamePiece is a UIView
[UIView animateWithDuration:7 animations:^{
CGRect frame = self.nowGamePiece.frame;
frame = CGRectMake(self.gameBoardImageView.center.x, self.gameBoardImageView.center.y, 500, 500);
self.nowGamePiece.frame = frame;
} completion:^(BOOL finished){
return;
}];
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.