In the development of iOS applications, I would like to place multiple UI Views on one view and assign a tap and long tap operation (Segue) to each.
Each UIView is assigned a tag.I was able to implement the tap using the UITouch method below, but I don't know how to implement the long tap
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
UITouch*touch=[touch anyObject];
switch(touch.view.tag){
case1:
// What to do when a tag of 1 is tapped?
appDelegate.locno=@"1";
[self performSegueWithIdentifier:@"read" sender:self];
case2:
appDelegate.locno=@"2";
[self performSegueWithIdentifier:@"read" sender:self];
default:
break;
}
}
When you tap long,
appDelegate.locno=@"Tag Number";
[self performSegueWithIdentifier:@"write" sender:self];
What should I do if I want to run ?
ios objective-c iphone
Override touchesBegan:withEvent:
is basically only a special case, and it would be easier to use GestureRecognizer
.
There are many ways to tap, but UITapGestureRecognizer
.
Long taps can be detected by UILongPressGestureRecognizer
.
See the reference for more information on how to use it.
1235 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
758 Error in x, y, and format string must not be None
771 GDB gets version error when attempting to debug with the Presense SDK (IDE)
856 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2025 OneMinuteCode. All rights reserved.