How to write the manual AutoLayout constraint? - autolayout

I'm a novice iOS developer and I want to learn how to write the manual AutoLayout constraint. As I had found the link which visually allow how AutoLayout works. Please refer the below link for more information.
URL : https://autolayoutconstraints.com/
But it does not allow how it works when other component over there and their relation accordingly.
Thank you for such a prompt response, I wish I could be clearer on my issue.

I suppose by manual you mean apply constraints via Code.
Autolayout has been constantly evolving ever since it come to existence.
To apply constrains via code, you can use any of these three techniques. (Easiest and the newest technique at bottom)
Old verbose constraining using method, (constraintWithItem)
+(instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c
Visual Format Language
(https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html)
Layout Anchors (https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html#//apple_ref/doc/uid/TP40010853-CH16-SW5)
You can google the bold's to know more.
But these is nothing better than https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/index.html#//apple_ref/doc/uid/TP40010853-CH7-SW1
This document has examples that apply constraint, with other component (view) and their relations.

are you asking how to set up your constraint programatically? If yes do you plan on using the story board at all or implementing everything programatically?
if you want to do it all programatically it would look something like:
class someViewController: UIViewController{
let myLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "Hello"
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubView(myLabel)
myLabel.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
myLabel.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
myLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
myLabel.heightAnchor.constraint(equalToConstant: 50).isActive = true
}
}
This would create a label in your ViewController and pin it to the left right and bottom with a set height of 50 pixels. You can find any one of your constraints for the item by looking for it's anchor and setting it to the desired value. Make sure to set translatesAutoresizingMaskIntoConstraints to false otherwise your constraints won't be followed.

You can use a 3rd party library like Snapkit or SwiftyLayout.

Related

How to get CSS value for 'pointer' of the current device?

Based on this documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/#media/pointer
You should be able to programmatically react differently to different available pointer types using CSS. However, I felt like there used to be an easy way to test what pointer your current device was using but from looking around on Stackoverflow all over the place I can no longer find it. How can I achieve this and find out the current pointer value for my device?
Finally tracked it down
is_fine = matchMedia('(pointer:fine)').matches
is_coarse = matchMedia('(pointer:coarse)').matches
console.log(`is fine: ${is_fine}, is_coarse: ${is_coarse}`)
From: How to detect if pointer coarse or fine
Can add that you can do this for hover as:
can_hover = matchMedia('(hover)').matches
no_hover = matchMedia('(hover:none)').matches
console.log(`can hover: ${can_hover}, no hover: ${no_hover}`)

Random Godot beginner-question: en-/disable CheckButton

how can I enable or disable a CheckButton via code? Is there any simple way like "input pickable true/false" I use with collision shapes? I played around with control focus modes but didn't succeed.
For example: I'd like to have a timer starting when button down / holding down and after a certain time the button shouldn't react at release anymore. Just as if it was never put down in the first place...
There must be a simple command for that, right?
Edit:
Trying
my_button.disabled = true
leads to the error
Invalid set index 'disabled' (on base: 'GDScriptNativeClass') with value of type 'bool'.
It sounds like you're looking for the pressed property.
my_button.pressed = true
The documentation isn't very clear on the usage but it does what you're describing. https://docs.godotengine.org/en/stable/classes/class_checkbutton.html

Are there Tags that could solve this?

New to coding, trying to see what/if Tags would make this code work
So I'm a beginner with basic understanding and more of a Graphics/ Designer than code based. I found a codepen by WEDOO that has exactly what I need and want to try to just swap my "animationData" to see if I can get it to work and then modify it as needed for my test (will be assign the button code to various objects for the SVG). I Can't seem to find the right "Tags" or determine if its referencing an external script...I'd image it just needs the right information to function...is that correct?
Thanks in advance!
var animation = bodymovin.loadAnimation({
container: targetAnim,
path: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/914929/data-testo4.json...
My output from BodyMovin in a JSON file:
var animationData =
{"v":"5.4.2","fr":29.9700012207031,"ip":0,"op":149.000006068894...
Does it make sense to think that I need replace the var animation with info that should be the targetAnim with the code in the JSON file? So far put the var animationData breaks things and does nothing (visually).
The bodymovin.loadAnimation can be passed either a URL to a Bodymovin JSON via the path option OR you can pass the animation JSON inline by setting the animationData option instead.
In you case it would end up looking something like:
var animation = bodymovin.loadAnimation({
container: targetAnim,
animationData = {"v":"5.4.2","fr":29.9700012207031,"ip":0,"op":149.000006068894...
...
})

Looking for example of how to display text in an NSWindow programmatically?

I am trying to display text in a HUD style semi-transparent window. I have got the code for the window all set up, but I have been scouring the documents for two days now and haven't come up with a way that works to actually display text in the window. Since I am using AppleScriptObjC in Script Debugger, and not Xcode, I'd rather do this programmatically and not have to switch to Xcode and use IB. (I did spend some time messing around with IB, but it is not very intuitive to be honest. So I thought I would check this form before going through the guides on how to get started using IB).
So I was given some advice to "create an NSTextField and add it to your window's contentView". So I have tried many different set ups of trying to init a NSTextField (And NSTextView), and I may have been able to get that part correct, but getting the text to actually display in the window has been a bigger challenge than I expected. I have included a code snippit of the code I am using to generate the window.
tell (NSWindow's alloc()'s ¬
initWithContentRect:{{theWidth, theHeight}, {640, 480}} ¬
styleMask:NSBorderlessWindowMask ¬
backing:NSBackingStoreBuffered ¬
defer:true)
setOpaque_(yes)
setAlphaValue_(0.5)
setBackgroundColor_(NSColor's grayColor())
setReleasedWhenClosed_(yes)
setExcludedFromWindowsMenu_(yes)
orderFrontRegardless()
delay 1
|close|()
end tell
My hope is to be able to get an NSText View in that Window in order to display some text in it. So far I haven't come close. The errors I generally get are about "unrecognized selector sent to instance". So it is pretty obvious that I am doing something wrong. I hope there is an easy way to accomplish this that I haven't yet come across.
It sounds like there isn't a target for some of the methods. In a tell statement, usually the target is implied, but sometimes AppleScript can't figure it out. You also don't get the newer method syntax, so I've had better luck just specifying the target for everything - also note that object properties can usually be set directly instead of using their setter method.
I can't tell from your snippet, but you also need to add the textView to the window's contentView, for example:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
# create a text view
tell (current application's NSTextView's alloc's initWithFrame:{{20, 20}, {600, 440}})
set theTextView to it
end tell
# create a window
tell (current application's NSWindow's alloc()'s ¬
initWithContentRect:{{200, 600}, {640, 480}} ¬
styleMask:(current application's NSBorderlessWindowMask) ¬
backing:(current application's NSBackingStoreBuffered) ¬
defer:true)
set theWindow to it
set its opaque to true
set its alphaValue to 0.5
set its backgroundColor to (current application's NSColor's grayColor)
set its releasedWhenClosed to true
set its excludedFromWindowsMenu to true
end tell
theWindow's contentView's addSubview:theTextView
theTextView's setString:"this is a test"
theWindow's orderFrontRegardless()
delay 5
theWindow's |close|()

Google maps API v3 - externally controlling radius on distanceWidget

this seems pretty specific to ask - but there was no other alternative to the expertbase of stackoverflow!
I'm stuck in a problem where I need to control the radius of the circle by an external means such as a dropdown or a textbox.
I had a hard time doing the circle and had to copy stuff from the Twitter search example on:
http://code.google.com/apis/maps/articles/mvcfun/twittersearch.html
Ideally, I would like to know how to bind an external even to the radiusWidget, the problem is - the sizer inside the radiusWidget seems a private entity.
It would be awesome if someone could hit me in the face with a bang!
Thx
distanceWidget.set('distance', XXX) should work. If you read the MVC article you can see how the binding is bi-directional.
You can look at the source of the Twitter example by downloading it to your computer, as you likely already did. When you have the source you can adapt it to your purposes as you like. The software usage rights (terms of usage, license, etc), if they are any, have to be respected of course.
In the case of the RadiusWidget you would just do:
function RadiusWidget(opt_distance) {
// ...
this.sizer = this.addSizer_(); // sizer is now accessible in RadiusWidget
}
RadiusWidget.prototype.addSizer_ = function() {
var sizer = ...
// ...
return sizer;
}

Resources