How to NSAnimationEffect in swift - swift

I'm trying to play an animation when I remove an item from a NSTableView by dragging the item out of the window.
According to the documentation, its usually done using. NSAnimationEffect.
These effects are used to indicate that an item was removed from a
collection, such as a toolbar, without deleting the underlying data.
See NSShowAnimationEffect(::::::).
But I'm not sure how to use this.

Didn't notice that NSAnimationEffect had a show() method. That seems to do the trick.
let loc = NSEvent.mouseLocation
NSAnimationEffect.poof.show(centeredAt: NSPoint(x: loc.x, y: loc.y), size: NSSize(width: 40, height: 40))
}

Related

how to make UIVIEW in custom style?

i have to make this type of UIView and there is a image view in the top.
i am new in swift so kindly suggest me the best Answer for it.
I guess that there are many resources on how to design views in swift. But to give you quick advice, the first method is use storyboard and place an image with proper constraints.
The second one is to do it programmatically, by implementing UIView variable and assigning an image to id. Something like this:
private func constructView() {
let myImage = UIImageView(image: "name of image inserted to assets folder in xcode")
myImage.frame = CGRect(x: 200, y: 64, width: 30, height: 30)
container.addSubview(myImage)
}

Add a popup text view to a SpriteKit game

I am creating a SpriteKit game and want to be able to take advantage of textAlerts - like all the games I grew up playing. I also want them to be flexible so I can subclass them and add them throughout my game - I am not sure how to do this and so would be very grateful of any advice.
There are a number of ways that I have started to look into:
Use another SKScene
The idea here would be to add another scene immediately on top of our current one. This would have a faded out background and would be configured with the text to be displayed. This seems like the wrong approach
Use an SKNode
I could create a custom node and initialise it with my specific text. I would then disable movement and add the node at the bottom of the screen. I would then customise the actions that occur when it is tapped.
Use an SKLabel
SKLabels are designed to show text so these seem like a promising place to look. The issue is that I want to add an image into the popup view (this a headshot of the person you are talking to) and so it doesn't feel like I should be able to inject an image in.
Use something else
I don't know what this might be. Is what I am trying to do easy or harder than I think?
My problem is that I come from a swift background so am struggling to convert to a SpriteKit mindset. In Swift I would put together a custom UIView with all the UIKit components and add it to the screen. In SpriteKit we don't have the same tools so I don't know the right combinations to put together what I want.
Ideally I want to be able to configure the text popup with an array of text so that a conversation can be had with the user tapping for each new line.
Edit 1: What I have tried so far
Based on #ElTomatos comment I have experimented with adding a SKSpriteNode and an SKLabelNode on top of each other using the following code:
guard let camera = camera else { return }
let dialogueBackground = SKSpriteNode(texture: nil, color: .red, size: CGSize(width: screenSize.width / camera.xScale, height: screenSize.height / 3 / camera.xScale))
dialogueBackground.anchorPoint = CGPoint(x: 0, y: 0)
dialogueBackground.zPosition = 50
dialogueBackground.position = CGPoint(x: -screenSize.width, y: -screenSize.height)
camera.addChild(dialogueBackground)
let label = SKLabelNode(text: "Hello world")
label.zPosition = 100
label.position = CGPoint(x: -screenSize.width, y: 100 - screenSize.height)
camera.addChild(label)
As you can see the view doesn't go to the edge of the screen. Is this something to do with the safe area? It's difficult to get the width and height as the camera doesn't have a CGSize we can use.

Changing the separator color of UINavigationBar

I’m working on a iOS-App based on Xcode’s “Master-Detail Template” and want to use custom colors for some of the UI elements.
However, I couldn’t find out how to change the right separator of the UINavigationBar:
I’ve already tried to change the backgroundColor of UINavigationBar, UINavigationItem and its titleView but without success.
Would be great if someone has a clue.
EDIT:
I’ve just noted that viewed in vertical mode, it’s the whole separator that I want to ink?
A slight modification of this answer gives you
extension UINavigationBar {
func setRightBorderColor(color: UIColor, width: CGFloat) {
let rightBorderRect = CGRect(x: frame.width, y: 0, width: width, height: frame.height)
let rightBorderView = UIView(frame: rightBorderRect)
rightBorderView.backgroundColor = color
addSubview(rightBorderView)
}
}

Why are UIScreen.bounds incorrect in iOS11

Please don't mark as duplicate. Available threads haven't provided an answer. Behavior is iOS11 only.
Updating a project from Xcode 8 to Xcode 9, using now iOS11 but still Swift 3, I have the following experience:
print("UIScreen.main.bounds.width = \(UIScreen.main.bounds.width)")
print("self.view.frame.width = \(self.view.frame.width)")
let rect = CGRect(
x: 0,
y: 0,
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height * 0.25
)
prints:
UIScreen.main.bounds.width = 414.0
self.view.frame.width = 600.0
The view is supposed to be from screen edge to screen edge. Therefore I have used UIScreen.main.bounds.width. But the value far too small for the actual view controller size of self.view.frame.width.
Why is that? What am I missing? Help is very appreciated.
Physical device. Same behavior using UIScreen.main.bounds.width
I had a similar problem with incorrect fetching of UIScreen.main.bounds size. The size was less than a physical screen. The solution was to add the next line into info.plst:
Key:
Launch screen interface file base name
Type:
String
Value:
LaunchScreen
So check your info.plist to see if it contains this line. If it's not, just add it. Hope this helps.
screen shot of info.plst

missing argument for parameter 'coder' in call Swift

In my code I'm getting:
missing argument for parameter 'coder' in call swift
I'm a beginner to Swift and I've already tried everything including researching this question, but have found no answer. Thanks.
The code I'm getting this error is:
let button: UIButton = UIButton(frame: CGRect(origin: CGPoint(x: ChecklistViewController().view.frame.width / 2 + 117, y: ChecklistViewController().view.frame.size.height - 70), size: CGSize(width: 50, height: 50)))
The error is suggesting that the compiler is having trouble figuring out which init method should be invoked, so it's assuming you meant to call init(coder:).
But let's set that aside for a second. First, let's simplify your statement to eliminate some "noise". Rather than using CGRect(origin:, size:), you might use CGRect(x:, y:, width:, height:). That would yield (separating it on separate lines to make it a little easier to read):
let button = UIButton(frame: CGRect(
x: ChecklistViewController().view.frame.width / 2 + 117,
y: ChecklistViewController().view.frame.size.height - 70,
width: 50,
height: 50)
)
Second, the problem here is that that ChecklistViewController() syntax isn't actually referencing your existing ChecklistViewController. Every time it sees ChecklistViewController() it's creating a new instance of that view controller (so you probably have three instances, the original one and the two you accidentally created here). That's certainly not what you intended. If you were doing this in, one of the instance methods of the view controller itself, you'd just reference self, e.g.:
let button = UIButton(frame: CGRect(
x: self.view.frame.width / 2 + 117,
y: self.view.frame.size.height - 70,
width: 50,
height: 50)
)
A more subtle problem is that this code will only work if the frame of the view has been set. But if you have this code in viewDidLoad, the frame hasn't been set yet. If you did this in viewDidAppear, though, you could get away with this code. Generally, you'd use auto layout, to avoid this, e.g. something like:
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
// do additional configuration of the button here
view.addSubview(button)
NSLayoutConstraint.activateConstraints([
button.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor, constant: 117),
button.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor, constant: -70),
button.widthAnchor.constraintEqualToConstant(50),
button.heightAnchor.constraintEqualToConstant(50)
])
Because we did this with auto layout, it means you can do this in viewDidLoad, if you want. Also, it means that if you rotate the device, the constraints will recalculate the frame automatically for you.
Having said all of this, the "missing argument for parameter 'coder'" might be a result of some other problem in the code. But, if you fix the declaration of the button, you might be able to better diagnose any other issue that might be in the code.
I think the problem is that you are using ChecklistViewController to generate your positions.
Try this code
let button: UIButton = UIButton(frame: CGRect(x: (CGRectGetMidX(self.view.frame) + 117) , y: (CGRectGetMaxY(self.view.frame) - 70) , size: CGSize(width: 50, height: 50)))