1

이 블록을 사용하여 텍스트에 펄스를 적용하고 텍스트를 움직이면 텍스트가 오른쪽으로 이동하고 뒤로 움직입니다. 그것이 인터페이스 빌더에 의해 추가되는 패딩이나 무언가 때문인 것 같습니다.레이블 애니메이션 움직이는 텍스트 - iOS

[UIView animateWithDuration:0.5 animations:^{ 
    // grow the label up to 130%, using a animation of 1/2s 
    myLabel.transform = CGAffineTransformMakeScale(1.3,1.3); 
} completion:^(BOOL finished) { 
    // When the "grow" animation is completed, go back to size 100% using another animation of 1/2s 
    [UIView animateWithDuration:0.5 animations:^{ 
     myLabel.transform = CGAffineTransformIdentity; 
    }]; 
}]; 

답변

2

돌아 오는 길에 앵커 포인트를 1.3 배 줄입니다.

CGPoint anchorPoint = myLabel.layer.anchorPoint; 
[UIView animateWithDuration:0.5 animations:^{ 
    // grow the label up to 130%, using a animation of 1/2s 
    myLabel.transform = CGAffineTransformMakeScale(1.3,1.3); 
} completion:^(BOOL finished) { 
    // When the "grow" animation is completed, go back to size 100% using another animation of 1/2s 
    myLabel.layer.anchorPoint = CGPointMake(anchorPoint.x/1.3, anchorPoint.y/1.3); 
    [UIView animateWithDuration:0.5 animations:^{ 
     myLabel.transform = CGAffineTransformIdentity; 
    }]; 
}]; 
+0

감사합니다. – TerryG

+0

이 작은 버그가 하나 있습니다. 블록을 더 많이 사용할수록 레이블이 오른쪽으로 크리프되어 원래 영역으로 다시 돌아 가지 않습니다. 나는 매번 0.06을 움직이는다고 생각합니다 .... – TerryG

+0

당신 말이 맞습니다. 대답이 정확하지 않습니다. 이 대답에 대해 승인 된 점수를 제거하십시오. 올바른 해결책이 있는지 확인하겠습니다. – Kedar

0

나는 코드를 시도했다. 텍스트가 제대로 레이블에 들어있는 레이블이나 텍스트 정렬 센터가있는 레이블에 대해서는 잘 작동합니다.

정적 또는 고정 텍스트가있는 라벨이있는 경우 내 배경은 라벨에 배경색을 지정하고 라벨 텍스트가 너무 크면 텍스트를 확인하여 텍스트가 제대로 레이블에 맞도록하십시오. 그러면 코드가 제대로 작동합니다.

이제 동적 텍스트는 다음

UIFont *font = [UIFont systemFontOfSize:9.0]; 
CGSize stringSize; 
stringSize = [myLabel.text sizeWithFont:font constrainedToSize:CGSizeMake(1000, myLabel.frame.size.height) lineBreakMode:UILineBreakModeWordWrap]; 

그런 다음 mylabel 폭으로 stringSize.width을 할당 아래에 동적으로 라벨 폭을 계산하려고해야합니다. 여기서는 레이블의 너비를 동적으로 변경합니다. 그러면 원하는대로 코드가 제대로 작동합니다.

0

그런 다음 원래 크기

[UIView animateWithDuration:0.5 animations:^{ 
      myLabel.transform = CGAffineTransformMakeScale(1.3,1.3); 
     } completion:^(BOOL finished) { 

       [UIView animateWithDuration:0.5 animations:^{ 
       myLabel.transform = CGAffineTransformMakeScale(1,1); 
       myLabel.hidden=YES; 
      }]; 
     }]; 
에 이미지를 축소합니다 먼저 130 %로 이미지를 확대합니다, 나는 그것을 당신을 도울 것이라고 생각이 코드를 시도해야합니다 -이 당신의 코드를 변경
관련 문제