gpt4 book ai didi

ios - 添加滑动手势以在详细 View 中显示下一个项目

转载 作者:行者123 更新时间:2023-11-29 13:06:39 25 4
gpt4 key购买 nike

从 Collection View 中,我已经通过 segue 将我想要的详细信息传递给详细 View Controller 。

    - (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;


}

我现在想向目标 View Controller 添加一个滑动手势,这样我就可以在不返回主页的情况下转到下一篇文章。我添加了以下内容来设置手势。

     UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizer];
}

-(IBAction)swipeHandler:(UISwipeGestureRecognizer *)sender{
NSLog(@"SWIPE");

}

但是,我不知道如何离开这里。有人能指出我正确的方向吗。

最佳答案

我在这里尝试做的是通过滑动播放一系列图像。

-(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];

关于ios - 添加滑动手势以在详细 View 中显示下一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18457487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com