我正在使用第三方库,当用户平移视图时使用它(使用UIPanGestureRecognizer
)
但是,我想在按钮点击时调用此方法。因此,我如何在代码中对panning
进行硬编码,因此我无需编辑3rd party library
。
换句话说,我如何以编程方式创建UIPanGesture
?
我希望我的问题很清楚,有人可以帮助我。
来自第三方库的代码:
- (void)vPannedHorizontally:(UIPanGestureRecognizer*)gesture
{
...
}
按钮Click ViewCOntroller
中的点击事件:
-(IBAction)clickedNow:(id)sender{
ThirdPartyLib *tpl =[[ThirdPartyLib alloc]init];
[tpl vPannedHorizontally: ??????]; // I need to hardcode a UIPanGesture so it works.
}
更新
#import "ContentViewController.h"
#import "PaperFoldView.h"
@interface ContentViewController ()
@property (nonatomic, retain) PaperFoldView *paperFoldView;
@end
@implementation ContentViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:@"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(flipView:)];
self.navigationItem.leftBarButtonItem = flipButton;
}
return self;
}
-(void)flipView:(id)sender{
NSLog(@"Hi");
[self.paperFoldView setPaperFoldState:PaperFoldStateLeftUnfolded animated:YES];
}
答案 0 :(得分:0)
每个手势识别器都会获得一个回调方法,当它们发生某些事件时,它们会响应(状态改变,......)。所以你的第三方图书馆必须有一个回调。通过回调,我的意思是[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panCallback:)]
,在这种情况下- (void)panCallback:(UIPanGestureRecognizer *)sender
将被调用实例化识别器的任何人。
您要做的是找出第三方库中回调的名称。然后创建一个UIPanGestureRecognizer
,您可以在其上设置所有必需的内容,例如翻译。
UIPanGestureRecognizer *reco = UIPanGestureRecnogizer.new;
[reco setTranslation:CGPointMake(20, 20) inView:self.view]; //Or whatever you want
//reco.state = UIGestureRecognizerStateChanged; //If you want this too you'll have to subclass it
//Now call the callback and pass your gesture recognizer
[my3rdLibraryClassInstance performSelector:@selector(panCallback:) withObject:reco];
希望这可以解决一些问题。
编辑:至于折叠库,我注意到有一些方法可以用来手工折叠。
paperFoldInitialPanDirection
animateWithContentOffset:(CGPoint)point panned:(BOOL)panned
并相应地设置点玩一下参数。我不确定它会起作用,但我认为应该(我只是快速瞥见了实施)。报告尝试时会发生什么。
编辑2:最终解决方案
如果要打开视图,库已经提供了执行此操作的方法。只需拨打
即可[self.paperFoldView setPaperFoldState:PaperFoldStateLeftUnfolded animated:YES];
这是通过包含的演示项目进行测试的。而且你已经完成了。
答案 1 :(得分:0)
我认为你不需要为此模拟手势。
调用PaperFoldView上的方法手动折叠/展开。
-(IBAction)open:(id)sender
{
//For some reason the timerStepDuration is set to 0 by default so you need to set this otherwise there won't be an animation.
self.paperFoldView.timerStepDuration = 0.02;
[self.paperFoldView setPaperFoldState:PaperFoldStateLeftUnfolded];
}
-(IBAction)close:(id)sender
{
//For some reason the timerStepDuration is set to 0 by default so you need to set this otherwise there won't be an animation.
self.paperFoldView.timerStepDuration = 0.02;
[self.paperFoldView setPaperFoldState:PaperFoldStateDefault];
}