嗨我正在开发一个应用程序.在那个我做了一个视图的动画从左到右和从右到左移动并更改该视图中包含的标签的值.但是当我点击向左或向右按钮时该视图被删除新视图覆盖旧视图.所以我不想覆盖.我想添加新视图.我的代码是
-(void)centerAnimation1:(id)sender
{
UIView *currentView = daysview;
theWindow = daysview;
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
animation.delegate = self;
[animation setDuration:0.4];
[animation setType:kCATransitionMoveIn];
if(rhtolft)
{
[animation setSubtype:kCATransitionFromLeft];
}
else
{
[animation setSubtype:kCATransitionFromRight];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
[currentView removeFromSuperview];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if(animate)
{
CATransition *animation = [CATransition animation];
animation.delegate = self;
[animation setDuration:0.4];
[animation setType:kCATransitionMoveIn];
if(rhtolft)
{
[animation setSubtype:kCATransitionFromLeft];
rhtolft=NO;
}
else
{
[animation setSubtype:kCATransitionFromRight];
}
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
animate=NO;
[self.view addSubview:daysview];
}
}
Run Code Online (Sandbox Code Playgroud)
我只是在左nad右键操作方法中调用centerAnimation1方法.调用此方法后,我更改了标签值.
SAM*_*HOD 20
试试这个
首先是L到R
CGRect basketTopFrame = Yourview.frame;
basketTopFrame.origin.x = 115;
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ Yourview.frame = basketTopFrame; } completion:^(BOOL finished){ }];
Run Code Online (Sandbox Code Playgroud)
然后R到L.
CGRect napkinBottomFrame = Yourview.frame;
napkinBottomFrame.origin.x = 0;
[UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ Yourview.frame = napkinBottomFrame; } completion:^(BOOL finished){/*done*/}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25929 次 |
| 最近记录: |