使用Worklight进行Hybird开发,Html5和Native切换时增加动画效果
在Worklight中使用Html5和Native进行Hybrid开发时,两者之间互相切换时比较生硬,用户体验非常一般。
其实,我们可以在两者直接切换时增加动画效果来解决此问题:
iOS上:
(1)从html5转到native时:Native的ViewController里重写onAfterShow方法,在里面增加动画代码:
-(void)onAfterShow{ [self showTransitionAnim]; } -(void)showTransitionAnim { CDVAppDelegate *cordovaAppDelegate =[[UIApplication sharedApplication] delegate]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[cordovaAppDelegate window] cache:YES]; [UIView commitAnimations]; }
(2)从Native返回Html5时,做如下处理:
-(void)naviClick:(UIButton *)sender { NSDictionary *dic = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:[sender tag]] forKey:@"index"]; // 显示动画 [self showTransitionAnim]; //返回web界面 [NativePage showWebView:dic]; }
Android:
(1)从html5转到native时:Native的Activity里在onCreate方法中增加动画代码:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //增加滑动切换动画 overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right); // Go fullscreen requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.front); }
(2)从Native返回Html5时,做如下处理:
private void returnToWeb() { Intent intent = new Intent(); intent.putExtra("index", index); setResult(RESULT_OK, intent); finish(); //增加滑动切换动画 overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right); }
相关推荐
wusiye 2020-10-23
表格的现在还是较为常用的一种标签,但不是用来布局,常见处理、显示表格式数据。在HTML网页中,要想创建表格,就需要使用表格相关的标签。<table> <tr> <td>单元格内的文字</td> ...
gufudhn 2020-08-09
nercon 2020-08-01
swiftwwj 2020-07-21
nercon 2020-07-16
饮马天涯 2020-07-05
Lophole 2020-06-28
gufudhn 2020-06-12
csstpeixun 2020-06-11
huzijia 2020-06-09
WebVincent 2020-06-06
行吟阁 2020-05-30
qsdnet我想学编程 2020-05-26
gufudhn 2020-05-25
qsdnet我想学编程 2020-05-19
suixinsuoyu 2020-05-15
HSdiana 2020-05-15
PioneerFan 2020-05-15