【发布时间】:2017-07-21 15:19:36
【问题描述】:
我想模拟向左滑动以显示在照片应用程序中看到的下一张图片,以便新图片使用动画从右向左滑入。
但是,就我而言,该视图包含不止一张照片。它还有一个标题。
只需在滑动时更新照片和文字,我就可以在没有动画的情况下做到这一点。这只是改变了屏幕上的照片和标题,但是没有从右到左的动画技术。
有没有办法显示旧视图向左移动,而新的更新视图从右侧移动。
以下内容将视图向左移动,但由于没有放置任何内容,因此将屏幕呈现为黑色。
//In handleSwipe called by gesture recognizer
CGRect topFrame = self.view.frame;
topFrame.origin.x = -320;
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.view.frame = topFrame; _myImage=newImage;
_mycaption=newcaption;} completion:^(BOOL finished){ }];
感谢您的任何建议。
编辑: 有问题的视图是您通过 segue 从 tableview 获得的详细视图。它目前已经使用滚动视图进行垂直滚动,因为内容可以在垂直维度上超过单个屏幕。
我找到了一种方法让旧照片和标题向左移动,而新照片和标题使用完成块从右边进入,但是,它不太令人满意,因为当两个动作之间存在间隙时屏幕是黑色的。这似乎是完成方法特有的,因为新图像在旧图像完成移动之前不会开始移动。
- (IBAction)swipedLeft:(id)sender
{
CGRect initialViewFrame = self.view.frame;
CGRect movedToLeftViewFrame = CGRectMake(initialViewFrame.origin.x - 375, initialViewFrame.origin.y, initialViewFrame.size.width, initialViewFrame.size.height);
CGRect movedToRightViewFrame = CGRectMake(initialViewFrame.origin.x + 375, initialViewFrame.origin.y, initialViewFrame.size.width, initialViewFrame.size.height);
[UIView animateWithDuration:0.1
animations:^{self.view.frame = movedToLeftViewFrame;
//above moves old image out of view.
}
completion:^(BOOL finished)
{
self.view.frame = movedToRightViewFrame;
[self loadNextItem];//changes pic and text.
[UIView animateWithDuration:0.1
animations:^{self.view.frame = initialViewFrame;
//moves new one in
}
completion:nil];
}];
}
【问题讨论】:
标签: ios objective-c animation