Ios 添加滑动手势以在详细视图中显示下一项
从集合视图中,我已通过segue将所需的详细信息传递给详细视图控制器Ios 添加滑动手势以在详细视图中显示下一项,ios,uigesturerecognizer,uicollectionview,Ios,Uigesturerecognizer,Uicollectionview,从集合视图中,我已通过segue将所需的详细信息传递给详细视图控制器 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { SportsCollectionViewCell *selectedCell = (SportsCollectionViewCell *)sender; SportsBrowserViewController *targetVC = (SportsBrowserViewCo
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SportsCollectionViewCell *selectedCell = (SportsCollectionViewCell *)sender;
SportsBrowserViewController *targetVC = (SportsBrowserViewController *) [segue destinationViewController];
targetVC.targetURL = selectedCell.targetURL;
targetVC.sdesc = selectedCell.description.text;
targetVC.stitle = selectedCell.title.text;
targetVC.simage = selectedCell.image.image;
targetVC.scat = selectedCell.category.text;
targetVC.sdate = selectedCell.date.text;
}
现在我想向目标视图控制器添加一个滑动手势,这样我就可以在不返回主页的情况下阅读下一篇文章。我添加了以下内容来设置手势
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizer];
}
-(IBAction)swipeHandler:(UISwipeGestureRecognizer *)sender{
NSLog(@"SWIPE");
}
然而,我不知道如何从这里开始。有人能给我指出正确的方向吗。如果你想用下一个项目的详细信息更新视图,在滑动手势处理程序中,你可以用下一篇文章的内容更新视图的内容。在执行此操作时,可以在同一视图中使用动画以使幻灯片生效 比如:
self.targetURL = newItem.targetURL;
self.sdesc = newItem.description.text;
self.stitle = newItem.title.text;
self.simage = newItem.image.image;
self.scat = newItem.category.text;
self.sdate = newItem.date.text;
如果要使用下一个项目的详细信息更新视图,可以在滑动手势处理程序中使用下一篇文章内容更新视图的内容。在执行此操作时,可以在同一视图中使用动画以使幻灯片生效 比如:
self.targetURL = newItem.targetURL;
self.sdesc = newItem.description.text;
self.stitle = newItem.title.text;
self.simage = newItem.image.image;
self.scat = newItem.category.text;
self.sdate = newItem.date.text;
我在这里尝试的是通过滑动播放一系列图像
-(IBAction)swipeHandler:(UISwipeGestureRecognizer *)gesture{
{
if(gesture.direction == UISwipeGestureRecognizerDirectionRight)
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
self.count--;
if (self.count<0)
{
self.count=[yourArticlesArray count];
// for round robin swiping.
}
CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromLeft;
[self loadArticleForIndex:self.count];
[targetVC.layer addAnimation:animation forKey:@"imageTransition"];
}
}
else
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
self.count++;
if (self.count>=[yourArticleArray count])
{
self.count=0;
}
CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromLeft;
[self loadArticleForIndex:self.count];
[targetVC.layer addAnimation:animation forKey:@"imageTransition"];
}
}
}
我在这里尝试的是通过滑动播放一系列图像
-(IBAction)swipeHandler:(UISwipeGestureRecognizer *)gesture{
{
if(gesture.direction == UISwipeGestureRecognizerDirectionRight)
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
self.count--;
if (self.count<0)
{
self.count=[yourArticlesArray count];
// for round robin swiping.
}
CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromLeft;
[self loadArticleForIndex:self.count];
[targetVC.layer addAnimation:animation forKey:@"imageTransition"];
}
}
else
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
self.count++;
if (self.count>=[yourArticleArray count])
{
self.count=0;
}
CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromLeft;
[self loadArticleForIndex:self.count];
[targetVC.layer addAnimation:animation forKey:@"imageTransition"];
}
}
}
如果您希望能够阅读下一篇文章,大概是下一篇文章,等等,那么您应该将整个数组(或填充表的任何内容)传递给detail controller以及所选单元格的indexPath(这样您就知道在数组中的何处可以获得第一篇文章) 如果您希望能够阅读下一篇文章,可能是下一篇文章之后的文章,等等,那么您应该将整个数组(或填充表的任何内容)以及所选单元格的indexPath传递给detail controller(以便您知道在数组中的何处可以获得第一篇文章) 如果你愿意,我可以编辑我的代码,这可能会对你有更好的帮助,如果你愿意,请告诉我。我正在努力,但仍然有点困惑。所以请编辑掉,这样我就能知道我该去哪里了。最奇怪的事情。我收到“未找到属性计数”错误。我是不是错过了什么?我仍然无法确定如何前进。我在另一个问题中发布了我的更新,因为我不知道如何在这里做到这一点。如果你愿意,我可以编辑我的代码,这可能会对你有更好的帮助,如果你愿意,请告诉我。我正在努力,但仍然有点困惑。所以请编辑掉,这样我就能知道我该去哪里了。最奇怪的事情。我收到“未找到属性计数”错误。我是不是错过了什么?我仍然无法确定如何前进。我在另一个问题中发布了我的更新,因为我不知道如何在这里做到这一点。我正在重新讨论这个问题,请您详细说明一下您的建议。要求是使用滑动手势从源视图移动到目标,从而生成幻灯片动画,并更新细节。因此,我建议更新内容,然后创建一个幻灯片动画,以在手势代理中提供相同的效果。我正在重新讨论这个问题,请您详细说明您的建议。要求是使用滑动手势从源视图移动到目标,从而生成更新细节的幻灯片动画。因此,我建议更新内容,然后创建一个幻灯片动画,以在手势代理中提供相同的效果。