我正在与Objective-C中的Nsgesturerenturercognizer一起玩。
我在XIB帆布上有一个简单的自定义视图,我将其应用到了,并在该XIB帆布上应用了压力,放大,放大和旋转手势识别器。我从每个appdelegate.m中创建了一个操作,然后向其添加代码。它们在某种程度上都起作用,但是放大和旋转的方式行为不满意我。
这是两者的代码:
- (IBAction)magnifyView:(NSMagnificationGestureRecognizer *)sender {
CGFloat magnification = sender.magnification + 1.0;
NSView *view = sender.view;
CGAffineTransform transform = CGAffineTransformMakeScale(magnification, magnification);
[[view layer] setAffineTransform:transform];
sender.magnification = 0;
}
... ...
- (IBAction)rotateView:(NSRotationGestureRecognizer *)sender {
CGFloat rotation = sender.rotation;
NSView *view = sender.view;
CGAffineTransform transform = CGAffineTransformMakeRotation(rotation);
[[view layer] setAffineTransform:transform];
sender.rotation = 0;
}
我使用的是MacOS 12.4和Xcode 13.4.1的2016 MBP来实现这一点,并使用手势的触控板,我看到 magnifyView
似乎结结巴巴,除非我强烈打开手指,以“脱节”手势,这可能会触发macos show桌面,而 rotateView
仅在回来之前旋转几个度。
可以找到整个项目,如果您想看看它。无论如何,它不包含太多其他,这是一个实验。
您能否让它看看(甚至只是上面的方法),并告诉我我可以做些什么来改进它?
谢谢你!
I'm playing with NSGestureRecognizer(s) in Objective-C.
I have a simple Custom View in the XIB canvas to which I applied the press, pan, magnify, and rotate gesture recognisers. From each one I have created an action in AppDelegate.m and then added code to it. They all work to some extent but the way magnify and rotate behave does not satisfy me.
Here is the code for both of them:
- (IBAction)magnifyView:(NSMagnificationGestureRecognizer *)sender {
CGFloat magnification = sender.magnification + 1.0;
NSView *view = sender.view;
CGAffineTransform transform = CGAffineTransformMakeScale(magnification, magnification);
[[view layer] setAffineTransform:transform];
sender.magnification = 0;
}
and ...
- (IBAction)rotateView:(NSRotationGestureRecognizer *)sender {
CGFloat rotation = sender.rotation;
NSView *view = sender.view;
CGAffineTransform transform = CGAffineTransformMakeRotation(rotation);
[[view layer] setAffineTransform:transform];
sender.rotation = 0;
}
I'm using a 2016 MBP with macOS 12.4 and Xcode 13.4.1 to realise this and, using the trackpad for the gestures, I see that magnifyView
seems to stutter unless I strongly open my fingers in an "unpinch" gesture—which risks triggering the macOS show desktop, while rotateView
only rotates of a few degrees before coming back.
The whole project can be found here, if you feel like giving it a look. It doesn't contain much else anyway, it's an experiment.
Could you please give it a look (or even just at the methods above) and tell me what I could do to improve it?
Thank you!
发布评论