uiresponder

nextResponder in Swift 3

本秂侑毒 提交于 2019-12-04 19:17:47
in Swift 2 this code works fine override func nextResponder() -> UIResponder? { // it's called when user make any touch event return super.nextResponder() } it's basically helps to get notification about any user interaction. in Swift 3 now it's a variable not a function and I can't even observe it with didSet. so how to use the code above in Swift 3 You can override the variable: override var next: UIResponder? { get { // do something return super.next } } As the variable is defined as a read-only variable, implementing didSet doesn't make sense. You're not supposed to set this variable.

How do I add the UIApplicationDelegate to the end of the UIResponder chain?

浪尽此生 提交于 2019-12-04 07:32:26
I'm trying to provide an IBAction method for common functionality that is required at various parts of the app. i.e. Login is implemented modally, and if it succeeds results in a notification that allows all loaded view controllers to react to this event (transition from anonymous to authenticated) @interface MyAppDelegate : NSObject <UIApplicationDelegate> { ... } - (IBAction)loginTapped:(id)sender; @end I set the action of that button to the First Responder in IB, however the responder chain doesn't give MyAppDelegate a chance to respond. My problem is that, I don't want to replicate the

How can I make a UIKeyCommand with the return/enter key?

隐身守侯 提交于 2019-12-03 23:35:13
问题 I'd like to make a UIKeyCommand that uses only the [return] key. So far I've tried: UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)]; There's no global constant for the enter key, like there is for up, down, left, right, and escape (from UIResponder.h ): // These are pre-defined constants for use with the input property of UIKeyCommand objects. UIKIT_EXTERN NSString *const UIKeyInputUpArrow NS_AVAILABLE_IOS(7_0); UIKIT

How to add tap gesture to UICollectionView , while maintaining cell selection?

妖精的绣舞 提交于 2019-12-03 23:25:56
问题 Task Add a single tap gesture to UICollectionView , do not get in the way of cell selection. I want some other taps on the no-cell part of the collectionView. Code Using XCode8, Swift 3. override func viewDidLoad() { ... collectionView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap))) } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { print(indexPath) } func tap(sender: UITapGestureRecognizer){ print("tapped") }

Passing touch events to appropriate sibling UIViews

匆匆过客 提交于 2019-12-03 11:23:55
I'm trying to handle touch events with touchesBegan in an overlay to a parent UIView but also allow the touch input to pass through to sibling UIView s underneath. I expected there would be some straight-forward way to process a touch event and then say "now send it to the next responder as if this one didn't exist", but all I can find is the nextResponder method which appears to be giving back the parent to my overlay view. That parent is then not really passing it onto the next sibling of that overlay view so I'm stuck uncertain how to do what seems like a simple task that is usually

iPhone: Click view behind transparent UIScrollView

蓝咒 提交于 2019-12-03 10:54:29
I have a UIScrollView that is set to have a clear background. Part of the scrollview does have content, but part does not (so it shows other views behind it). I would like to be able to click through the UIScrollView and to the MKMapView behind, but only for the transparent portion of the UIScrollView. I have found some code which I am having a real hard time understanding how to get working: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (![self yourMethodThatDeterminesInterestingTouches:touches withEvent:event]) [self.nextResponder touchesBegan:touches withEvent:event]

UIViewController with inputAccessoryView is not deallocated

本小妞迷上赌 提交于 2019-12-03 06:45:43
I have simple subclass of UIViewController (code below). If I attach inputAccessoryView, my viewcontroller is never deallocated. If I do not set inputAccessoryView in viewDidLoad, dealloc is called as expected. Am I missing something? @interface IMTestViewController : UIViewController @property (nonatomic, strong) UIView *messageInputView; @property(nonatomic, readwrite, strong) UIView *inputAccessoryView; @end @implementation IMTestViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]

Detecting continuous key presses with UIKeyCommand

人走茶凉 提交于 2019-12-03 05:58:38
问题 Is it possible to get continuous key presses? I'm using keyCommands : to intercept the arrows keys being pressed on an external keyboard, but I only get 1 call per press. I would love to get either multiple calls every X milliseconds as long as the key is held down, or calls when the key is pressed and when it’s released. Here's my code: - (NSArray *)keyCommands { UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow modifierFlags:0 action:@selector(upArrow:)];

How do Responder Chain Works in IPhone? What are the “next responders”?

北城以北 提交于 2019-12-03 04:50:32
问题 This is what the documentation says: If the first responder [to an event or action message] cannot handle an event or action message, it forwards it to the “next responder” in a linked series called the responder chain. The responder chain allows responder objects to transfer responsibility for handling an event or action message to other objects in the application. If an object in the responder chain cannot handle the event or action, it resends the message to the next responder in the chain

Dismiss keyboard with swipe gesture (as in Message app)

梦想的初衷 提交于 2019-12-03 02:18:25
问题 When the keyboard is showing on the iPhone's Messages app, if the user begins a swipe down from the messages tableview and continues into the keyboard area, the keyboard will begin to dismiss. If they move their finger up and down during this process, the keyboard moves with it. Are Apple doing this with private APIs, or is there a way to control the keyboard like this from (I presume) a gesture recognizer? 回答1: I created a UIView category that provides the desired functionality: https:/