반응형
두 숫자 사이에 UILabel 텍스트를 애니메이션 확장?
저는 iPhone 및 Mac 프로그래밍 (이전에 Windows 용으로 개발 됨)을 처음 사용하는데 질문이 있습니다.
Ease-Out 스타일 에서 5 에서 80 까지와 같이 두 숫자 사이 의 text
속성을 어떻게 애니메이션? 가능 ? Google에서 한 시간 동안 검색했지만 내 문제를 해결하는 것을 발견했습니다. 내가 원하는 것 : 간단한 게임을 위해 사용자의 돈을 애니메이션합니다. 애니메이션없이 50 에서 100까지 또는 그와 수준으로 가면별로보기 좋지 않습니다 .UILabel
CoreAnimation
방법을 알고있는 사람이 있습니까?
감사합니다!
자동 전환을 사용할 수 있습니다. 완벽하게 잘 작동합니다.
// Add transition (must be called after myLabel has been displayed)
CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.type = kCATransitionFade;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[myLabel.layer addAnimation:animation forKey:@"changeTextTransition"];
// Change the text
myLabel.text = newText;
이 코드는 myLabel이 이미 경우 작동합니다. myLabel.layer가 nil이되고 애니메이션이 객체에 추가되지 않습니다.
에 스위프트 4 관심 :
let animation: CATransition = CATransition()
animation.duration = 1.0
animation.type = kCATransitionFade
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
myLabel.layer.add(animation, forKey: "changeTextTransition")
잘 작동한다!
목표 -C
[UIView transitionWithView:self.label
duration:.5f
options:UIViewAnimationOptionCurveEaseInOut |
UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.label.text = rand() % 2 ? @"111!" : @"42";
} completion:nil];
빠른
UIView.transitionWithView(label, duration: 0.25, options: [.CurveEaseInOut, .TransitionCrossDissolve], animations: {
self.label.text = (arc4random() % 2 == 0) ? "111" : "222"
}, completion: nil)
PRTween 이라는 다양한 타이밍 함수로 값을 트위닝하는 훌륭한 엔진을 찾았 습니다 . 클래스를 설치하고 다음 줄을 따라 몇 가지 코드를 만듭니다.
- (IBAction)tweenValue
{
[[PRTween sharedInstance] removeTweenOperation:activeTweenOperation];
PRTweenPeriod *period = [PRTweenPeriod periodWithStartValue:0.0 endValue:100.0 duration:1.0];
activeTweenOperation = [[PRTween sharedInstance] addTweenPeriod:period
target:self
selector:@selector(update:)
timingFunction:&PRTweenTimingFunctionCircOut];
}
- (void)update:(PRTweenPeriod*)period
{
self.animatingView.center = CGPointMake(period.tweenedValue + 100.0, 200.0);
self.valueLabel.text = [NSString stringWithFormat:@"%.2f", period.tweenedValue];
}
나를 위해 대접을 작동합니다. :)
이전 번호를 밀어내는 새 번호로 발행 업 및 다운을 원하는 경우 (티커 등) :
let animation = CATransition()
animation.removedOnCompletion = true
animation.duration = 0.2
animation.type = kCATransitionPush
animation.subtype = newValue > value ? kCATransitionFromTop : kCATransitionFromBottom
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
valueLabel.layer.addAnimation(animation, forKey:"changeTextTransition")
Swift 2.0에서는 다음 UIView.transitionWithView()
방법을 사용합니다 .
UIView.transitionWithView(self.payPeriodSummaryLabel,
duration: 0.2,
options: [.CurveEaseInOut, .TransitionCrossDissolve],
animations: { () -> Void in
self.label.text = "your text value"
}, completion: nil)
참고 URL : https://stackoverflow.com/questions/5301305/animate-uilabel-text-between-two-numbers
반응형
'ProgramingTip' 카테고리의 다른 글
null 값에 대한 jdk8 스트림을 관리하는 방법 (0) | 2020.10.11 |
---|---|
속성 파일에서 등호 기호를 이스케이프하는 방법 (0) | 2020.10.11 |
평일의 특정 시간에 cron 탭 설정 (0) | 2020.10.11 |
IntelliJ에서 Maven 계층을 보는 방법 (0) | 2020.10.11 |
WiFi를 통해 adb를 사용하여 Android Studio에서 수행하는 방법 (0) | 2020.10.11 |