Should we use integer strictly when we layout controls in iOS? Why? - ios

I need to draw a line on the screen. The designer tell me to set the height of line to 2.5 pt. I'm wondering if it's acceptable to use decimal here.
I know it will be better if we use integer as the size or position of a UIView. But I can't tell why. I didn't find any convincing document about it.
So could anyone explain it or find something for me?
The only problem I know is UILabel with decimal size will be blurry. Is there any other problem like performance problem would happen?

As per your case it's just about half point which in my opinion should be ok. I often find that in storyboards my frames get moved 0.5 point up or down when I have lot of UI elements and sometimes constraints just get confused.
Additionally: the easiest scenario when your frame could be positioned at "some 0.5 point" is if you use a constraint to centre your view in it's superview. In this case the default x or y frame position could easily end up being "some 0.5 point". So it can happen often times and could be done by Xcode itself, so that's why I think your view will be just fine.
As stated previous in comments those points are CGFloat. What we have now is 1x, 2x and 3x resolutions. So there will always be the need for some calculations for at least one of the devices.
You may also look at this Screen resolutions guide to see all the time when up sampling and downsampling occurs.

Related

Suggestions for drawing a complex hierarchy at multiple sizes

I am trying to think of a way to render a sub-hierarchy that is somewhat complex, and would look good (crisp) when drawn at multiple scales.
I would expect there to be some container view with a size, and this subview could be constrained within it and drawn properly.
If it helps think of a hierarchy like a calculator keypad or computer keyboard even:
You would have a keyContainer view, and a bunch of key views (or layers) of various sizes and positions.
Suppose I wanted this to be drawn in a container that was 320 x 320. I was thinking if I knew the ratio of w:h for each key and I knew the ratio of a key's width to the width of the whole container, then I could work out the sizes and positions for the key. I've found in practice the math seems to introduce a lot of rounding errors and you end up on off-pixel boundaries so the final rendering does not look great.
So how would you tackle a problem like this?
Thanks for any ideas.

Square Cash Label Animation

Does anyone know how Square Cash animates their label?
The label does two things, appears to resize to fit the numbers on screen like SizeToFit might, but I don't believe that you can animate based on SizeToFit.
Secondly, numbers that disappear seem to animate downwards and disappear. Numbers that are entered animate down from above. That doesn't seem too tricky, but the comma does it too when we go from 4 digits to 5 digits!
I coded something similar and yes, it is very tricky to make it perfect.
It may help you to know that I used collection views. Then you can customise cell/layout transitions.
Hope this helps.
It would be helpful if you posted a short video so we could see the animation you are talking about.
Based on your description, I'm guessing that they build the full number themselves by putting a single digit/symbol on a layer (or view) and then animating each character separately.
If you have a separate tile for each symbol it is pretty easy to change the size of the previous tiles to make room for a new tile, and animate a new number tile down at the same time. You could do the animation with UIView animation or with a set of coordinated CABasicAnimations.
I know the answer is late but may be help to some other,
I developed demo screen similar to square cash you can check here

Cocoa iOS Make CGPoints "Bigger" in UIView

Is it possible to make the default CGPoint size for an iOS app "bigger"?
For example, the iPhone's main view is 320 points wide - is it possible to change that to, say, 100 points, and base all calculations on that 100 (as in still be able to use CGRectMake, get sizes etc. normally).
So does anyone know how to subclass UIView in such a way as to make the above work, and, more importantly, would Apple allow it?
Thanks for your time!
Apply a CGAffineTransformMakeScale(320/100, 320/100) transform to your view so that it is scaled, and 100 points will be scaled to 100 * (320/100) = 320 points wide.
Or course, don't use magic numbers like above, but use some constant for the value 100 and something like [UIScreen mainScreen].applicationFrame.size.width (or view.window.screen.applicationFrame.size.width or anything similar) to get the width of the screen instead of the value 320 (because magic numbers are bad, and we never know if the size of the screen will change in any future like the height just changed with iPhone5)
Have a look at UIViews transform property. But this is probably a bad idea: If you rescale your coordinate system, almost all your views are going to be misaligned with the screen's pixels. This will lead to blurry display of text, lines and other graphics.
Why would you want to do this in the first place?

How to set a cross hair icon in exact middle of the camera overlay?

I would think MyImagePicker.frame.center is where I should place the icon (subtract icon.size.width/2 and height /2., but when the picture actually saves, what I thought the cross hair is pointing at is not the middle of the image at all. X seems okay, but Y happens to be some distance off. I can approximate by trial and error, but I would like to be exact.
Help?
The frame actually defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view as detailed here.
You most likely want to use MyImagePicker.bounds.size.width / 2 and MyImagePicker.bounds.size.height / 2 to get the actual center of your image picker.
I actually learned this recently by watching the Stanford lecture series on iOS 5 development on iTunes U.

Is Interface Builder Really Pixel Accurate?

I often find I need to programmatically nudge GUI elements around programmatically after I lay them out in IB. Can someone please give me the low down on the pixel accuracy of IB?
Adobe Illustrator? Pixel accurate. IB? Hmmm ...
Thanks,
Doug
it should be as pixel accurate as laying the objects out in code. If you find yourself needing to nudge the items. It may be because the content placed in them is making them a different size.
In the Size Inspector check out the Auto Sizing options. Perhaps you are expecting them to be center aligned when they are actually left aligned.

Resources