In iOS I used to use:
#IBOutlet weak var mainTextField: UITextView!
let newPosition = mainTextField.beginningOfDocument
mainTextField.selectedTextRange = mainTextField.textRange(from: newPosition, to: newPosition)
But NSTextView has no member 'beginningOfDocument'. How can I get the same result?
moveToBeginningOfDocument(_:) is what you're looking for.
Searching the documentation for 'beginningOfDocument' should find it but it doesn't.
Related
I tried to implement a game in arkit, when user tap the screen, the bullet will be fired from the touched position.
I know how to get 2D position on the screen
as below
void HandleTapGesture(UITapGestureRecognizer sender)
{
let scnView = sender.view as! ARSCNView
let holdLocation = sender.location(in: scnView)
but I don't know how to transfer this position into the world position.
Then I can use it in below scenario
let bullet = SCNNode(geometry: SCNSphere(radius: 0.08))
bullet.position = ?
That position type is
open var position: SCNVector3
Can anyone share any opinion? Many thanks.
I have two scroll views, one of them with constraints that make it take up the full parent view, and the other right next to it, but hidden outside the bounds of the parent view. I want to animate both sliding left until the second scroll view takes up the full parent view, and the first scroll view is now out of bounds on the left. How do I do this for an OS X app using Swift?
Figured this one out with a little hunting and piecing things together.
Create an IBOutlet for the constraints that you want to change in the animation. In this case, use the leading constraint for each scroll view.
#IBOutlet weak var ScrollView1LeadingConstraint: NSLayoutConstraint!
#IBOutlet weak var ScrollView2LeadingConstraint: NSLayoutConstraint!
Then, use the following:
NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = //length of the animation time in seconds
self. ScrollView1LeadingConstraint.animator().constant = //negative width of scroll view
self.ScrollView2LeadingConstraint.animator().constant = 0
}, completionHandler: { () -> Void in
//insert any completion code here
})
This will animate the first scroll view out of frame on the left, and move the second scroll view into its former place.
Does anyone know how to create the following? I cannot find any tutorials.
I can get the effect without a slider, but it is not as smooth. Or I can incorporate the slider but not update the picker with the value as it expects CGPoints instead of Ints and expects it in the gesture.locationInView(colorWheel) format, which a standard CGPoint will not accept.
You can use Cocoa controller for this. There are so much of controllers which is similar to this interface.
https://www.cocoacontrols.com/controls/hsv-color-picker
hope this link will help you.
I was able to just use the color wheel as a background and used the slider value to change the hue
func changeSet(changeValue: CGFloat) {
var value = (360 - currentAngleGlobal) / 360 // I had to deduct from 360 as my values were inverted
var color = UIColor(hue: CGFloat(value), saturation: 1, brightness: 1, alpha: 1)
self.colorOutput.backgroundColor = color
}
I've added a NSToolbar to my window and inserted some items. Two of them contain a custom view (NSTextFiled as a label and a NSButton). I've set a maximum and minimum width for both these items and they display fine but they are much larger than needed making the label and especially the button annoyingly big with undesired space.
I'm looking for a way to set the width of button and its item to the minimum required by the text it contains.
After playing around I've added an outlet also for the NSToolbarItem and used the following function to change the text:
#IBOutlet weak var manageSessionItem: NSToolbarItem!
#IBOutlet weak var manageSession: NSButton!
func setManageSessionTitle(title: String) {
let s: NSString = title
let attr=[NSFontAttributeName: manageSession.font!]
//Add width to compensate for button graphics
let w=s.sizeWithAttributes(attr).width + 20
manageSession.frame.size.width = w
manageSessionItem.minSize.width = w
manageSessionItem.maxSize.width = w
manageSession.title = title
}
I have 4 containers and need to move them up 40 pixels together. Can i move all of them at once.
I have tried changing the rect of them one by one, but when rotation occurs everything is messed up.
It is very easy actually. In IB create your top, bottom, left and right constraints with heights as well. And then ctrl drag the top constraint with connects the top view to the top of the superview.
Go to your class and just give the desired constant value as you wish.
#IBOutlet weak var moveConstant: NSLayoutConstraint!
and then
#IBAction func moveTop(sender: AnyObject) {
moveConstant.constant = 40
}