UITapGestureRecognizer not working on older version of ios - ios

I'm working on a view that has a subview which outlet is viewRect. I programmatically added UITapGestureRecognizer on that view to perform a task.
It works fine on ios 10.3.1 (iPhone 5) but not in iOS 9.2.1 (iPhone 5).
UITapGestureRecognizer *mTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(showView)];
[mTapGestureRecognizer setNumberOfTouchesRequired:1];
[self.viewRect addGestureRecognizer:mTapGestureRecognizer];
self.viewRect.userInteractionEnabled = YES;
method to respond
-(void)showView {
NSLog("tapped on view");
}
Can't figure out why this not working.

Related

Why doesn't a Mac Catalyst app use numberOfTouchesRequired?

I'm porting apps from iOS to Mac using Mac Catalyst and noticed that two- and three-finger tap gestures don't work. Here's some example code:
UIView *test = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
test.backgroundColor = [UIColor redColor];
[self.view addSubview:test];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(toggleColumns:)];
gesture.numberOfTouchesRequired = 2;
gesture.delegate = self;
[test addGestureRecognizer:gesture];
If I tap the red box with two fingers on my Magic Trackpad, nothing happens. The target method isn't called, nor are the gesture delegate methods like gestureRecognizer:shouldReceiveTouch:. However, if I comment out the numberOfTouchesRequired line, then a one-fingered tap works.
I don't see anything about this limitation in the documentation, and apparently it's not a general limit with multi-touch because a UIPinchGestureRecognizer works as expected. Am I missing something, or should I file a bug report?
Mac Catalyst seems to respond to a two finger click to show a UIContextMenuInteraction.
If you implement this, you can use this for showing a menu for a two finger click. Here is a decent tutorial.
Note: I am using mac catalyst in "Scale Interface to Match iPad" mode.

iPhone X - UITableView not displaying all separator lines

I created a entirely new Single View project in Xcode 9.3
I changed viewDidLoad in ViewController as follows:
I am missing some separator lines in the tableView shown below on iPhone X / iOS 11.3 simulator.
This issue does not exist with other iOS versions like iOS 10.x
What do I need to do to get all separator lines?
(void)viewDidLoad {
[super viewDidLoad];
UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 300, 500) style:UITableViewStylePlain];
[self.view addSubview:tv];
tv.backgroundColor = [UIColor redColor];
tv.separatorColor = [UIColor blueColor];
}
The simulator is scaled. Because of that, it isn't pixel perfect and the tableView lines will sometimes not be shown. This is why it's always best to do the final test on a real device when you can.

How to handle the conflicts between UITapGesture and 3D Touch in iPhone 6s/6s plus?

UITapGesture works OK for me before I tried it on iPhone 6s.
Please find the below code.
tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 1;
[self addGestureRecognizer:tapGesture];
Then, I met this issue, the handleTapGesture will not be invoked in iPhone 6s. I think it's because the Force Touch functionality of iPhone 6s.
Anybody know how to fix this? Thanks.

Come back to app from an other app

Hello,
When we are phoning with us iphone and you left the call view to come back at springboard, we can come back to the call view with the status bar. (This picture can better explain : http://what-when-how.com/wp-content/uploads/2011/08/tmpB178_thumb.jpg)
Or, in the Facebook app when you go to the messenger Facebook app (not same app) we can touch status bar to comme back Facebook App too.
I would like to know if it's possible to make it in my app ? And if it's possible, how I will proceed ? (Edit: I want co come back in my app from another app such Youtube.)
Thanks
Once you become familiar with how to open another app within your current app form following link:
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
You can simply create a view that has tap gesture and use it as a button
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
UIView *tapToReturnButton = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
tapToReturnButton.backgroundColor = [UIColor blueColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(tapToReturnButtonClicked)];
[tap setNumberOfTouchesRequired:1];
[tapToReturnButton addGestureRecognizer:tap];
UILabel *tapToReturnLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 20)];
tapToReturnLabel.text = #"Tap to return";
tapToReturnLabel.textColor = [UIColor whiteColor];
tapToReturnLabel.textAlignment = NSTextAlignmentCenter;
tapToReturnLabel.font = [UIFont fontWithName:#"ArialMT"
size:14];
[tapToReturnButton addSubview:tapToReturnLabel];
[self.view addSubview:tapToReturnButton];
}
- (void)tapToReturnButtonClicked
{
NSLog(#"Now you add your code that opens another app(URL) here");
}
Edited:
After I posted the code above I kind of realized that there will be no tap gesture on the status bar even though other bottom part (20 pixel) of tapToReturnButton has a click gesture. After I did some research, I think following link has the better solution on click gesture. I will probably use tapToReturnButton as placeholder to let users know where to touch though and remove UITapGestureRecognizer *tap.
How to detect touches in status bar
Again, I think there is multiple way to achieve your need but those links above will give you good starting point.
URL schemes will allow you to launch an app from an another app.
Check the following links for more info:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW18
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50
here are some system supported URL schemes
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899

A UIButton above a UIPickerView

I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it.
and here is my code where I initiate a UIPickerView as well as its dismiss button:
- (UIPickerView *)creatPickerView {
UIPickerView *tempPickerView = [[[UIPickerView alloc]
initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
tempPickerView.showsSelectionIndicator = YES;
tempPickerView.delegate = self;
tempPickerView.dataSource = self;
UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
[pickerButton setBackgroundImage:[UIImage imageNamed:#"hidePicker.png"]
forState:UIControlStateNormal];
[pickerButton addTarget:self action:#selector(hidePicker)
forControlEvents:UIControlEventTouchUpInside];
[tempPickerView addSubview:pickerButton];
[pickerButton release];
[self.view addSubview:tempPickerView];
return tempPickerView;
}
and it works well on my iPhone 4.3 Simulator, like this:
apparently there is a button on the upper right of the pickerView,
problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView.
Can anyone help me with this?
Thanks a lot and a lot!
I found the reason, it seems the png has some problem,
after I change another png, it comes up in the screen!
but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness.
But anyway the pickure is only a small problem.

Resources