我已经为一个UILongPressGestureRecognizer分配了两个UIButton对象。
第一个名为longPressGestureRecognizer,具有minimumPressDuration = 0.5
第二个,命名为prolongedPressGestureRecognizer,具有minimumPressDuration = 1.5
self.longPressGestureRecognizer = [UILongPressGestureRecognizer alloc initWithTarget:self action:@selector(longPress:)];
self.longPressGestureRecognizer.delegate = self;
self.longPressGestureRecognizer.minimumPressDuration = 0.5;
self.longPressGestureRecognizer.numberOfTouchesRequired = 1;
self.longPressGestureRecognizer.numberOfTapsRequired = 0;
self.longPressGestureRecognizer.allowableMovement = 10.0;
[self.customButton addGestureRecognizer:self.longPressGestureRecognizer];
self.prolongedPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(prolongedPress:)];
self.prolongedPressGestureRecognizer.delegate = self;
self.prolongedPressGestureRecognizer.minimumPressDuration = 1.5;
self.prolongedPressGestureRecognizer.numberOfTouchesRequired = 1;
self.prolongedPressGestureRecognizer.numberOfTapsRequired = 0;
self.prolongedPressGestureRecognizer.allowableMovement = 10.0;
[self.customButton addGestureRecognizer:self.prolongedPressGestureRecognizer];设想方案:
当第一次开火的时候,我想让事情发生。
当第二次触发时,我希望上下文菜单显示。
目前,我没有办法这样做。
解决办法:
2.是否可以以编程方式显示菜单?
NSMutableArray* actions = [[NSMutableArray alloc] init];
[actions addObject:[UIAction actionWithTitle:@"Edit"
image:nil
identifier:nil
handler:^(__kindof UIAction* _Nonnull action) {
// ...
}]];
UIMenu* menu =
[UIMenu menuWithTitle:@""
children:actions];
self.customButton.menu = menu;发布于 2022-09-23 20:11:06
你可能需要这样的东西。self.layoutButton将菜单显示为主要操作。意思是普通的水龙头。不是一个主要的动作是一个很长的敲打。
NSMutableArray<UIAction *> *actions = [NSMutableArray array];
__weak __typeof__(self) blockSelf = self;
for (NSString *type in sortedKeys) {
ZoneLayout *layout = [LayoutManager layoutByType:type];
UIAction *action = [UIAction actionWithTitle:layout.title image:nil identifier:type
handler:^(__kindof UIAction * _Nonnull action) {
__strong __typeof__(blockSelf) strongSelf = blockSelf;
if (strongSelf) {
strongSelf.layoutType = type;
[strongSelf setupZoneLayoutMenu];
}
}];
if ([self.layoutType isEqualToString:type])
action.state = UIMenuElementStateOn;
else
action.state = UIMenuElementStateOff;
[actions addObject:action];
}
ZoneLayout *layout = [LayoutManager layoutByType:self.layoutType];
if (layout != nil)
[self.layoutButton setTitle:layout.title forState:UIControlStateNormal];
else
[self.layoutButton setTitle:@"-" forState:UIControlStateNormal];
self.layoutButton.menu = [UIMenu menuWithChildren:actions];
self.layoutButton.showsMenuAsPrimaryAction = YES;https://stackoverflow.com/questions/73832252
复制相似问题