【问题标题】:How Change the Quotes By gesture [duplicate]如何通过手势更改报价[重复]
【发布时间】:2013-04-01 05:45:06
【问题描述】:

我正在创建在属性列表中有引号的应用程序,当我按下下一个按钮时,它会显示在 UIText 中,另一个引号会出现在 textview 中,但现在我想在用户根据该动作向左或向右滑动时添加手势引号会变得 。我是 iphone 新手。我已经使用viewpagger在android中完成了它。有没有人知道这个我该怎么做..提前谢谢。

【问题讨论】:

标签: iphone ios ios4


【解决方案1】:

您可以使用 UISwipeGestureRecognizer 来完成。 确保您的 textView 不可编辑。

代码如下:

UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe)];
[leftSwipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[_textView addGestureRecognizer:leftSwipe];


UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe)];
[rightSwipe setDirection:UISwipeGestureRecognizerDirectionRight];
[_textView addGestureRecognizer:rightSwipe];

- (void) leftSwipe
{
    NSLog(@"leftSwipe");
}

- (void) rightSwipe
{
    NSLog(@"rightSwipe");
}

现在相应地显示您的报价。

【讨论】:

    【解决方案2】:

    为您的报价添加动画:

    首先将 QuartzCore 框架导入您的项目。

    #import <QuartzCore/QuartzCore.h>
    

    现在修改滑动方法如下:

    - (void) leftSwipe
    {
    NSLog(@"leftSwipe");
    
    [self curlAnimationFromLeft];
    }
    
    - (void) rightSwipe
    {
    NSLog(@"rightSwipe");
    
    [self curlAnimationFromRight];
    }
    
    
    - (void) curlAnimationFromLeft
    {
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setDuration:1.0];
    [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
    animation.type = @"pageCurl";
    animation.subtype = @"fromRight";
    animation.fillMode = kCAFillModeForwards;
    [animation setRemovedOnCompletion:YES];
    [_textView.layer addAnimation:animation forKey:@"pageCurlAnimation"];
    }
    
    -(void)curlAnimationFromRight
    {
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setDuration:1.0];
    [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
    animation.type = @"pageUnCurl";
    animation.subtype = @"fromRight";
    animation.fillMode = kCAFillModeForwards;
    animation.startProgress = 0.35;
    [animation setRemovedOnCompletion:NO];
    [_textView.layer addAnimation:animation forKey:@"pageUnCurlAnimation"];
    }
    

    【讨论】:

    • Prashant,我在动画 setTimingFunction:UIViewAnimationCurveEaseInOut 附近遇到错误,它说隐式转换 NSinteger。
    • 你添加框架了吗?
    • 是的,我已经添加了
    • 是您可能在 .m 文件中导入的文件。但是已经为它添加了框架?
    • 我找到了解决方案而不是我添加的函数,因为它是 ARC 版本 [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2015-10-11
    相关资源
    最近更新 更多