Objective-C를 처음 사용했습니다. 3 개의 버튼을 위로 움직이는 애니메이션을 만들었습니다. 이 버튼에는 이미지가 포함되어 있습니다. 그러나이 버튼 애니메이션이 발생하면 버튼 이미지의 크기가 조절되어 커다란 이미지를 만듭니다. 아래의 코드를 수정하여 버튼 이미지의 크기를 조정하려고했지만 여전히 거대한 버튼이 있습니다. 누군가 나를 도울 수 있습니까? 너비 : 78 높이 : 76. 너비와 높이를 바꾸려고했지만 여전히 작동하지 않습니다. 참고 : 코드를 수정하면 완전히 다른 답변이 필요하지 않습니다.프로그래밍 방식으로 단추 애니메이션 크기를 조정하는 방법
-(IBAction)Search:(id)sender {
CGFloat screenWidth = self.view.bounds.size.width;
CGFloat screenHeight = self.view.bounds.size.height;
CGFloat normalizedX = (124/320); // You calculate these 'normalized' numbers, possibly from a designer's spec.
// it's the percent the amount should be over, as number from 0-1.
// This number is based on screen width of 320 having x 124 pt.
CGFloat startingX = normalizedX * screenWidth;
CGFloat startingY = (475/200) * screenHeight;
CGFloat width = (42/40) * screenWidth;
CGFloat height = (30/30) * screenHeight;
CGRect startingRect = CGRectMake(startingX, startingY, width, height);
self.button.frame = startingRect;
self.buttonTwo.frame = startingRect;
self.buttonThree.frame = startingRect;
// animate
[UIView animateWithDuration:0.75 animations:^{
CGFloat firstX = (13/770) * screenWidth;
CGFloat lowerY = (403/370) * screenHeight;
self.button.frame = CGRectMake(firstX, lowerY, width, height);
CGFloat secondX = (124/424) * screenWidth;
CGFloat upperY = (347/447) * screenHeight;
self.buttonTwo.frame = CGRectMake(secondX, upperY, width, height);
CGFloat thirdX = (232/680) * screenWidth;
self.buttonThree.frame = CGRectMake(thirdX, lowerY, width, height);
}];
}
버튼을 동일한 startRect로 즉시 이동 한 다음 다른 대상에 애니메이션을 적용 하시겠습니까? 크기가 전혀 바뀌 길 바래요? 코드를 게시하면 버튼 크기가 명확하게 조정되고 @ DuncanC의 관찰 결과는 부동 소수점 연산에 관한 것입니다. 버튼을 고정 된 크기로 유지하려면 프레임에서 CGRectOffset을 사용하면 원점을 조작 할 수 있습니다. – danh