从Collection View我已经通过segue将详细信息传递给了详细视图控制器。
- (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");
}
但是,我不知道如何离开这里。有人能指出我正确的方向。
答案 0 :(得分:1)
我在这里尝试做的是通过滑动播放一系列图像。
-(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"];
}
}
}
所以我建议删除我的部分,并加载你的部分文章,比如说我们有计数变量并且猜测你会把你的文章放在一个数组中,或者你可以写一个像这样的方法,
- (void)loadArticleForIndex:(int)index
{
//draw ur article or load your webview.
if(index>0 && index <[yourArticleArray count])
{
//instead of selectedCell take out articles from the array and feed it to your VC properties.
self.targetURL = selectedCell.targetURL;
self.sdesc = selectedCell.description.text;
self.stitle = selectedCell.title.text;
self.simage = selectedCell.image.image;
self.scat = selectedCell.category.text;
self.sdate = selectedCell.date.text;
//do something after setting all stuff.
}
}
因此,在滑动期间准确计算计数并将计数传递给函数,如
[self loadArticleForIndex:count];
答案 1 :(得分:0)
如果您想要使用下一个项目的详细信息更新视图,请在滑动手势处理程序中使用下一篇文章内容更新视图内容。您可以在同一视图中使用动画来同时生成幻灯片。
类似的东西:
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;
答案 2 :(得分:0)
如果您希望能够转到下一篇文章,并且可能是之后的文章,等等,那么您应该将整个数组(或者您正在填充表格的任何内容)传递给详细控制器以及所选单元格的indexPath(因此您知道数组中的第一篇文章的位置)。