XCode 10 adding action to button - swift

I'm trying to make a Cocoa app with buttons that run simple command line scripts.
I can't seem to figure out how to add the action to my button.
I've read some docs that suggest holding down option and dragging the button into controller code but I think they are out of date. Can someone suggest how to get there from this screenshot?

You need to first select your button, then hold the control ⌃ button on your keyboard and then drag that across to your view controller. That will then give you the option of what to name your method etc.

Actually I had the same problem and the root cause was just the drag method. From the descriptions I had assumed that I need to press CTL and then drag while having the left mouse button pressed. This did not work at all (in my environment). Then I noticed that "it works" with the right mouse button. But the result was not correct. (E.g. I could not get "Action"). Finally I found: I have to use the right mouse button only for dragging without holding CTL. Then I got the correct result.

Related

Unity Add Shooting Controller - easy one

I am very new to unity, and still learning how to create games and edit scripts, so this will probably be easy for anyone to answer. I don't really know what you want to see.
I have a script for using the left mouse button to fire. I want to add one for the right mouse button.
What I've done:
I copied the script that calls the objects and changed the name to Fires.
I added the controller button
I copied the same lines for Fire (original) in the Input manager script. changed the names to Fires.
The problem: pressing right mouse button doesn't do anything. If I use the Input Manager to call Fires, it works, but not when I press the button. I'm missing something, but I'm not sure what.
Any help would be appreciated.

NSButton in Swift, handle click and release events

i'm trying to manage different state of a simple push button on an OS X application : When the user click on it, and when the user release the click.
Currently i set my button type by NSMomentaryLightButton
NSMomentaryLightButton When the button is clicked (on state), it
appears illuminated. If the button has borders, it may also appear
recessed. When the button is released, it returns to its normal (off)
state.
This type of button is best for simply triggering actions because it
doesn’t show its state; it always displays its normal image or title.
This option is called Momentary Light in Interface Builder’s Button
inspector
I thought it was the good way, but when i print my button status, it's like a toggle button than the push button that i set. As you can see on exemple gif
To sum up, How can i have a real push button behaviour ? Call function when the user click on it, and when the user release the click.
Thank,
You don't want to use buttons for piano keys. First, they are non-rectangular, and they don't act as buttons do: neither single-action push-button, nor toggle switches. You are interacting in a custom way, with a custom view, meaning the NSButton control hierarchy isn't called for. Instead you're subclassing NSView and capturing low-level mouse events as detailed here:
https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/10000060i-CH6-SW1
You found this yourself as you detailed in your own comments, but I wanted to make sure you had a higher level point of view. It's even possible, and probably best, to consolidate all of the piano keys into a single view, and let the keys themselves be rendered using NSBezierPath and perform mouse hit detection using containsPoint:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/#//apple_ref/occ/instm/NSBezierPath/containsPoint:
This is a lot more work but the only way to make a truly professional looking piano simulation. Then you can render the keys with whatever outline, fill, and labeling you need without the limitations of built-in button shapes and layout. You could even have the bottom edges of the keys slightly rounded, for example, or apply a shiny texture.

Button with lost focus using PerspectiveTrasnform

Well, I make a Pane based on an example of JavaFX samples (Display Shelf), I put Panes with Labels, Buttons, ComboBox, TableView where's the ImageView. It is working, when I click on Pane, it does the animation correctly, but the buttons that I put in vertical on Right of Pane, receive the focus out of where they are. When I move the mouse button, nothing happens, but if I move the mouse to down of it, I can click in the button that so reveice the focus. The local where I have to move the mouse to button to receive the focus is increasingly far (down) if the button is below the other.
I'm using the Perspective Transform of JavaEX and all is in JavaFX Samples, just changed some params of size (width and height). This effect may be interfering in focus? Or can be another problem? If anyone already had this problem please help me. Thanks.

how to do tooltip on button in iphone?

I am having download icon on my page i want that when the user takes his finger over the button a tooltip should show as showing download in text.
is there any option in iphone to show a tooltip???
Dan is absolutely right on how to do it but I'd answer you should rethink your design to not need the tooltip at all.
There's a reason that there isn't one by default - what if the user presses down on the button to see what it does, reads the tooltip and realises that's not what they want. They then have to be very careful not to let go while still over the button or it will press and do the wrong thing. (And most users don't know that they can press down over a button, move their finger off it and release it to cancel the press.)
You should rethink your design to make it obvious what the buttons do without the user having to interact with them first.
However, if you definitely still want a tooltip, Dan's method is fine.
Nothing built-in, no. If you think about it, generally a tooltip appears when you mouse over the target item. There's no "mousing over" with a touch interface.
You can definitely roll your own, though. Start by placing a view containing your tooltip contents exactly where you want it with an alpha of 0%. Make a custom button with no content that outlines your download icon, and hook its "touch down inside" action to a method that animates the tooltip view to an alpha of 100%. Hook your button's "touch up inside" , "touch down outside" and "touch up outside" actions (and maybe some others--you might want to experiment with that) to a method that animates the tooltip view back to an alpha of 0%.
There isn't native support for this in iOS. But you can create your own.
I ended up creating my custom tooltip/popover class.
Can be initalised with any content view and dynamically adjusts it's frame.
Hope it helps.
https://github.com/akeara/AKETooltip

which UIButton event can act as a mouse over event like in flash

i would like to create a UIButton it will zoom in when mouse over it,can anyone tell me which event can do this
There is no mouse, only touches. How can you hover over a button without tapping it on a touch based interface? I dont think it works the way you think it does.
Hop into interface builder. Drop in a button and look in the attribute window.
You'll see the section that has Title: Image: Background. If you click on the drop down that says 'ALL', you can select several button states and set them accordingly. Use the highlighted state for when the user presses down on the button.
This should get you to understand how it works. You can dig into the docs to find out how to do it programaticaly from there.
Hover on the iPhone is a touch. Unless you're tracking where the finger is and you want objects to react when you enter their bounds. But the highlighted state should get you there.