nativescript
Nativescript로 애니메이션 구현하기
수색…
StackLayout의 배경 애니메이션
애니메이션 태핑 버튼에서 스택 레이 아웃의 배경색
pages / main.component.ts
import {Component, ElementRef, ViewChild} from "@angular/core";
import {Color} from "color";
import {View} from "ui/core/view";
@Component({
selector: "main",
template: `
<StackLayout #el>
<Button text="Apply Changes" (tap)="changeBgColor()"></Button>
</StackLayout>
`,
styleUrls: ["pages/main/main-common.css"],
})
export class MainComponent {
@ViewChild("el") el: ElementRef;
changeBgColor() {
let el = <View>this.el.nativeElement;
el.animate({
backgroundColor: new Color("#222"),
duration: 300
});
}
}
페이지 / main-common.css
StackLayout{
background-color: #333;
}
애니메이션 타이밍 기능 및 애니메이션 속성 사용
pages / main.component.ts
import {Component, ElementRef, ViewChild} from "@angular/core";
import {View} from "ui/core/view";
import {AnimationCurve} from "ui/enums";
@Component({
selector: "main",
template: `
<StackLayout>
<Image #img src="~/assets/images/user-shape.png"></Image>
<Button text="Apply Changes" (tap)="animateImage()"></Button>
</StackLayout>
`,
styleUrls: ["pages/main/main-common.css"],
})
export class MainComponent {
@ViewChild("img") img: ElementRef;
animateImage() {
let img = <View>this.img.nativeElement;
img.animate({
translate: { x: 0, y: 120 },
duration: 2000,
curve: AnimationCurve.easeIn
});
}
}
다른 애니메이션 속성의 #snippet
cubicBezier를 사용하여 자신의 타이밍 함수를 작성할 수도 있습니다.
- 큐빅 베 지어 사용
img.animate({
translate: { x: 0, y: 120 },
duration: 2000,
curve: AnimationCurve.cubicBezier(0.1, 0.2, 0.1, 1)
});
- 애니메이션 속성
불투명
img.animate({
opacity: 0,
duration: 2000
});
옮기다
img.animate({
translate: { x: 120, y: 0},
duration: 2000
});
규모
img.animate({
scale: { x: 1.5, y: 1.5},
duration: 2000
});
회전
img.animate({
rotate: 270,
duration: 2000
});
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow