我有一个带有标签的视图控制器,我想在该标签上向右执行平移。
所以我到目前为止所做的是:
*将平移手势添加到nib文件中的标签
*创建了一个didPan方法:
- (IBAction)didPan:(UIScreenEdgePanGestureRecognizer *)sender;
和实施:
- (IBAction)didPan:(UIScreenEdgePanGestureRecognizer *)sender {
CGPoint newTranslation = [sender translationInView:self.homeLabel];
self.homeLabel.transform = CGAffineTransformMakeTranslation(newTranslation.x, 0);
}
并将屏幕边缘平移手势识别器更改为右侧。
我认为现在应该平息,但现在,我做错了什么?
TNX
答案 0 :(得分:0)
所以我有时间自己尝试一下。
这里是Interface Builder与-didPan IBAction连接的样子。
然而,这对我没有用。我做了一些搜索,并在StackOverflow上也发现了这一点。
Possible bug with UIScreenEdgePanGestureRecognizer in Interface Builder
所以,我建议你尝试在代码中以旧方式实现它。
试试这个:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIScreenEdgePanGestureRecognizer *swipeFromLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
swipeFromLeft.edges = UIRectEdgeLeft;
[self.view addGestureRecognizer:swipeFromLeft];
UIScreenEdgePanGestureRecognizer *swipeFromRight = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
swipeFromRight.edges = UIRectEdgeRight;
[self.view addGestureRecognizer:swipeFromRight];
}