Xcode UIButton appear and disappear TitleLabel Value (button.titleLabel.hidden YES NO) - xcode

I have a one UIButton with a value, when you start the app, the TitleLabel of the button has been Hidden “call” (button.titleLabel.hidden=YES).
I have connected the button with a one IBAction (TouchDown) for when the user press the button appear the value / “call” (button.titleLabel.hidden=NO) and disappear with one NSTimer in 3 seconds after call (button.titleLabel.hidden=YES)
If you press one time the button is work good, (appear and disappear) but when you press without release the button and you move outside area and return inside area of the button the Value of Title appear again. Not work (button.titleLabel.hidden=YES)
I tested with another IBAction (Drag enter, Drag exit) in parallel to force the (button.titleLabel.hidden=YES) but the Value of the Title appear. Also take out the Timer but not working…
Please could you help me.
Thanks
Edit.

you must have created the button via Storyboard/XIB. Please check the sent events by right-clicking the button and set it to touch down. This should resolve the problem. :)

Related

How do I prevent the menu bar from moving down when my popover is open?

I have an app with a popover that appears on a status bar item. The thing is, when you click on the icon while you're in a full screen app, then move the mouse away from the menu bar to click on something in the popup, the menu bar moves up, and so does the popup. It's annoying.
Anyone know of any way to solve this? I've tried attaching an invisible menu to the popup, but I can't get the menu to be invisible.
Screenshot for clarity, the annoying part is where I wave my mouse around:
The popover window is moving because its parent window is the status item window, and when the parent window moves, the child moves with it. (Before I investigated this, I didn't even know Cocoa had parent and child windows.) I solved the problem with this code immediately after showing the popover:
NSWindow *popoverWindow = self.popup.contentViewController.view.window;
[popoverWindow.parentWindow removeChildWindow:popoverWindow];
Now, the menu bar still moves up, but at least the popup stays in the same place.
Either use Carbon events or watch for things happening to the menu bar (window of type NSStatusBarWindow):
Notifications of type
NSWindowDidChangeOcclusionStateNotification
NSWindowDidMoveNotification
NSWindowWillCloseNotification
NSWindowDidCloseNotification
with an object of class NSStatusBarWindow should give you enough information about the menu bar showing or hiding to add proper handling.
Super-hacky approach:
Custom window with some super-high window level to make it appear over the menu bar, then add a transparent custom view to the new window that catches and handles/blocks mouse clicks according to your needs.
Or:
Get the window instance the popover is using to display and track/handle NSWindowWillMoveNotification / NSWindowDidMoveNotification.
I converted #tbodt's answer to Swift 4 and confirmed that is resolves this issue:
let popoverWindow = popup.contentViewController.view.window as? NSWindow
popoverWindow?.parent?.removeChildWindow(popoverWindow!)

Image changing while pressed

I have 2 images for a JComponent, one of an unpressed button, and one of a pressed button. When I click the button, I want the image to change for the pressed one, but only while I am clicking. Which means whenever I release the mouse button, the image goes back to the unepressed button.
How can I do this?
Using a JButton, set the standard and pressed icons.

UITextField keyboard dosen't work any more

Please need help : I have two textfield in a view , save button and done button. now first time when I run my app, and type in a textfield the keyboard apperas good and I can save. but when I press done button to exit that view , the keyboard don't appears any more in any other part in my app.
just a shot in the dark here, but try to use
[textField resignFirstResponder];
in the done action

How do I stop my NSbutton from being selected when the app starts by default?

I created a button, and a have a little problem: When the my app launches, the button is selected. How do I disable this selection?
Example:
Caveat: This answer is incomplete: It just hides the focus ring (without preventing the selection). There's little benefit in this solution.
Set your button's focus ring type to none:
[myButton setFocusRingType:NSFocusRingTypeNone];
You can also set this option in the XIB.
First, you should know that, by default, buttons can't get focus. A user would have to have selected System Preferences > Keyboard > Shortcuts > Full Keyboard Access: All Controls. If they've done that, they may want a button to initially have focus.
Anyway, the proper way to do this is to call [theWindow makeFirstResponder:nil] sometime after showing it the first time. When to do this depends on exactly how the window gets shown. If you show it explicitly in code, then you can make the call just after that. If it's shown because its Visible at Launch flag is set in its NIB, then you'd do it after the NIB is loaded. Etc.
Something should always be first responder in a window, if anything can be. Normally, only a few controls like text fields can become first responder, but when a user has Full Keyboard Access enabled, it's normal for a button to be selected by default.
If you don't want this particular button to start selected, set the window's initialFirstResponder to another control.
I'd advise against using -[NSWindow makeFirstResponder:nil]. The window will start with nothing selected, but the button will become selected as soon as the user hits tab. This is unusual for Mac apps because there's no way to get the window back into the "nothing selected" state as a user.

iPad "dismiss keyboard" button (lower right), how do I detect when this occurs? What function tells me it was pressed?

I have an ipad app that when you are in landscape view, the view will move up when the keyboard is brought in. When you press done on the keyboard, textFieldShouldReturn and textFieldShouldEndEditing are called in which case, I move the view down in shouldEndEditing.
If the user presses the dismiss keyboard button, the keyboard does poof, yet the view is still stuck floating where I moved it.
I need to know how or what function is called when that button is pressed so I can redirect the function to textFieldShouldEndEditing.
Thanks!
You can listen for keyboard hide UIKeyboardWillHideNotification notification.
Example code is here http://developer.apple.com/iphone/library/samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html
When the "lower keyboard" button is pressed, the textfield delegate method of:
-(BOOL)textFieldShouldReturn:(UITextField *)textField
Won't be called.
When either the "lower keyboard" or "return button" are pressed, the:
-(void)textFieldDidEndEditing:(UITextField *)textField
Will be called.
I use a variable NSString *lowerKeyboardButtonPressed initially set to #"" which I set to #"N" in the textfieldShouldReturn method ... then in the textFieldDidEndEditing method I check to see if it is set to #"N" ... then I know if the return key or lower keyboard key was pressed. The last line in my textFieldDidEndEditing method sets the variable back to #"".
If you press the keyboard dismiss button and you have a hardware keyboard attached, then the willHide will only be called if you don't have an input accessory view. At which point you need to adjust in the willShow as well (which will have a negative difference between the UIKeyboardFrameBeginUserInfoKey and UIKeyboardFrameEndUserInfoKey keys).

Resources