- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有几个手势识别器来左右滑动图像或 vv,具体取决于滑动方向。但我希望动画更流畅。这是我到目前为止的代码:
-(void)swipeNext:(id)sender{
//0 Get the currentview as referenced by pageControl
UIImageView *oldView = [views objectAtIndex:currentViewIndex];
//MOVE ON TO NEW VIEW
currentViewIndex ++;
NSLog(@"left swiped - currentViewIndex:%d", currentViewIndex);
UIImageView *newView = [views objectAtIndex:currentViewIndex];
//NSLog(@"views objectAtIndex = %@",[views objectAtIndex:[self.pageControl currentPage]]);
//1 Animate out the old view
newView.frame = oldView.frame;
newView.center = CGPointMake(oldView.center.x + CGRectGetWidth(oldView.frame), oldView.center.y);
[oldView.superview addSubview: newView];
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn //UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
newView.center = oldView.center;
oldView.center = CGPointMake(oldView.center.x - CGRectGetWidth(oldView.frame), oldView.center.y);
}
completion:nil];
}
我想让它更快一点。我已经发布了我试图模拟的应用程序 DunkinDonuts ( What kind of viewcontrollers does the Dunkin Donuts app use ) 的引用,它们似乎使用了 UIPageControl,我一开始尝试使用它,但无法确定滑动的方向 ( How do I animate a UIImageView left to right with UIPageControl? ),所以我切换到手势。但如果您看到他们的应用程序,滑动速度会更快。
最佳答案
我发现要添加格式正确(可读)的代码块,我无法使用注释。有人建议我使用答案作为我原来问题的更新。所以就在这里。
更新
我这样修改了我的代码。与往常一样,viewDidLoad 调用 createUIViews 来执行以下操作:
-(void)createUIViews{
UIImage *image1 = [UIImage imageNamed:@"GiftCard.png"];
firstView = [[UIImageView alloc] initWithImage:image1];
CGRect newFrame1 = firstView.frame;
newFrame1.origin.x = 50;
newFrame1.origin.y = 10;
firstView.frame = newFrame1;
UIImage *image2 = [UIImage imageNamed:@"MyCard.png"];
secondView = [[UIImageView alloc] initWithImage:image2];
CGRect newFrame2 = secondView.frame;
newFrame2.origin.x = 350;//CGRectGetWidth(firstView.superview.frame)/2;
newFrame2.origin.y = 10;
secondView.frame = newFrame2;
//Add all Views offscreen except #1
[self.scrollView addSubview:firstView]; //added ONSCREEN
[self.scrollView addSubview:secondView]; //added OFFSCREEN
}
这会将第一个 View 设置在屏幕上,将第二个 View 设置在右侧。
手势识别器也在viewDidLoad中设置。他们调用 swipeNext 如下:
-(void)swipeNext:(id)sender{
//0 Get the currentview as referenced by pageControl
oldView = [views objectAtIndex:currentViewIndex];
//MOVE ON TO NEW VIEW
currentViewIndex ++;
newView = [views objectAtIndex:currentViewIndex];
//1 Animate out the old view **(Aaron, youre right, dont need this anymore)**
//newView.frame = oldView.frame;
//newView.center = CGPointMake(oldView.center.x + CGRectGetWidth(oldView.frame), oldView.center.y);
//[oldView.superview addSubview: newView];
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
newView.center = oldView.center;
oldView.center = CGPointMake(oldView.center.x - CGRectGetWidth(oldView.frame), oldView.center.y);
}
completion:nil];
}我注释掉了 addSubview,因为我将其移至 createUIViews 方法。它的工作原理是一样的,我认为这只是速度问题或我缺少的一些动画功能。我希望我可以添加视频。最初的 DD 应用程序看起来比 UIPageControl 更快地制作动画(我认为)这是视频的链接。 Sluggish iOS UIView Animation
关于ios - 如何让UIView动画更流畅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423868/
我是一名优秀的程序员,十分优秀!