问题
I have having two components in my app.
I need to animate the transition between these those pages.
I need to flip the page 1 and then page 2 should appear.
I there any plugin to do it in ionic 2.
Any reference/example will be appreciated.
I am using this.navController.setRootPage(Page2)
to go from one page to another.
回答1:
I don't know the Ionic framework, but here's a demo (plunker) how it works with plain Angular2: http://plnkr.co/edit/yJHjL5ap9l4MwOimCyyY?p=preview
Using the animations
feature of the Component decorator:
Component A
@Component({
selector: 'home',
directives: [ROUTER_DIRECTIVES],
template: `
<div class="radibre">
Home page
</div>
`,
styles: ['.radibre { width: 200px; height: 100px; background: red; color: white; }'],
host: {
'[@routeAnimation]': 'true',
'[style.display]': "'block'",
'[style.position]': "'absolute'"
},
animations: [
trigger('routeAnimation', [
state('*', style({transform: 'translateX(0)', opacity: 1})),
transition('void => *', [
style({transform: 'translateX(-100%)', opacity: 0}),
animate(1000)
]),
transition('* => void', animate(1000, style({transform: 'translateX(100%)', opacity: 0})))
])
]
})
export class Home {
constructor() { }
}
Component B
@Component({
selector: 'page',
template: `
<div class="page">Another page</div>`,
styles: ['.page { width: 200px; height: 100px; background: green; color: white; }'],
host: {
'[@routeAnimation]': 'true',
'[style.display]': "'block'",
'[style.position]': "'absolute'"
},
animations: [
trigger('routeAnimation', [
state('*', style({transform: 'translateX(0)', opacity: 1})),
transition('void => *', [
style({transform: 'translateX(-100%)', opacity: 0}),
animate(1000)
]),
transition('* => void', animate(1000, style({transform: 'translateX(100%)', opacity: 0})))
])
]
})
export class Page {
constructor() { }
}
来源:https://stackoverflow.com/questions/39000962/animating-transition-from-one-component-to-another-in-ionic-2