How to detect rounded screen corners in iOS - ios

On (https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x) Apple tells us that "A full-width button appearing at the bottom of the screen looks best when it has rounded corners and is aligned with the bottom of the safe area..."
So I want to round the corners of my button if the corners of the screen are round, but have sharp corners when the screen corners are sharp.
I would just check to see of the app is running on an iPhone X, but I expect that future devices will also have rounded corners and I don't want to have to revisit this code every time a new device comes out.
I have already checked window.layer.cornerRaidus in my app delegate...

Instead of detecting rounded corners, detect a non-zero region under bottom safe area. If this region is big enough, align to it (but obviously not in it), and perhaps round the button corners as your random bet on the future. If not, leave the standard auto-layout bottom margin under your button and use the standard button UI.
Whatever you do, be aware the Apple might or will change their UI guidelines and UI APIs and appearances, so don't plan on your future-proof design being future-proof.

Considering how we have to check whether we are on iphone-x (e.g., see this SO answer), I don't think there is and soon will be a clean way of finding this out.
Moreover, in my opinion, existence of safe area indicates that it is undesirable to detect this. Safe area is a rectangle into which you can draw, and you should not draw outside of it, or I would even say you should not even care about what is there (or what is not there).
Excerpt from Positioning Content Relative to the Safe Area:
Safe areas help you place your views within the visible portion of the overall interface.
That is what is guaranteed to be usable for your layout, and you should not really care about the outside of it.
Regarding the guidelines you cited:
Inset full-width buttons.
A button that extends to the edges of the screen might not look like a button. Respect the standard UIKit margins on the sides of full-width buttons. A full-width button appearing at the bottom of the screen looks best when it has rounded corners and is aligned with the bottom of the safe area—which also ensures that it doesn't conflict with the Home indicator.
Notice that there is no mention there of the rounded corners of the screen. So while it is kind of a fair assumption that that was the reason behind them recommending this layout, I would not prematurely try to generalize it yet.

Related

iOS segmented control with a little triangle on top

How can I draw a little triangle above the selected item in a UISegmentedControl? Does anyone know an open-source than extends it?
(if not - pointers of how to do it)
Design should look like (this is in the bottom of the screen)
I don't believe there's a native way to do that. You can either find a library that allows for it, but you can do it yourself fairly easily, which I recommend.
I can think of a few out of the box ways to approach it, here at the two I think worth mentioning off the bat:
1) Use UISegmentedControl with images. Make the segmented controller have a height that includes the triangle, and have an image for selected and normal states that shows what you want. The Normal states would have a rectangle of transparency on top, as wide as the entire image and as tall as the triangle. The selected image would include the triangle. Both images should end up the same width and height.
2) Subclass UISegmentedControl and do some custom drawing in drawRect:. You could draw the triangle outside (above) the bounds of the segmented controller, make sure to set the segmented controller's clipToBounds property to NO, as well as its layer's masksToBounds property.
If you'd like more help, or some other suggestions, just ask.

Guidance - Custom UICollectionView animation

I am looking for guidance with how to approach the following animation scenario.
I have UICollectionView with a custom circular UICollectionViewLayout subclassed layout. There are (circular) images around the perimeter of the circle and a 50% larger (circular) image in the center of the circle.
When the user taps one of the perimeter images, I want the tapped on image to move toward the center (becoming 50% bigger) and sort of "connect with" the center image. I then want the two images to float to the top of the view. (The bottom portion of the view will then be a context of things related to the two joined images).
If this makes sense to anyone, I'd really appreciate a starting point of some kind.
By the way, I'm an old developer but new to iOS and developing in Swift (but can read Objective-C).
Thanks!
I solved this using a visual trick. Of course, I'm sure there's a better way.
When one of the perimeter circles is tapped, I transition to a view controller that immediately creates a duplicate of the center circle and the tapped circle in their former locations, making it appear that the other elements disappeared.
I then simultaneously animate the tapped circle to the center and the center image to the top of the view. I enlarge the tapped circle briefly and then animate it to the top of the view next to the center circle restoring the tapped image's original size.
Not elegant but it works.

UIPopoverBackgroundView border shrink

I have subclassed and am using UIPopoverBackgroundView in order to make custom appearances for my UIPopoverControllers. Everything seems to work great so far, the popover draws well and looks the way I expect it.
The issue is that, when my popover is left open for a period of time with no activity, the border will often suddenly be drawn wrong. This specifically seems to only happen when the popover contains a scrollview/tableview which is larger than the popover (i.e. it is scrollable). It also doesn't happen every time, but if it does happen, it occurs in less than one minute of inactivity. If I take a screenshot, the issue is not visible (despite it clearly being seen on screen) so I can't provide any images of the issue unfortunately.
Does anyone know of any reason why the border would be drawn incorrectly after several seconds of inactivity and how to fix the issue? I can provide snippets of code if necessary, though I'm fairly certain everything is right (and equivalent to the many examples I've seen online). I also do not resize the popover at any time during the inactivity (I do resize when initially displayed to fit the content up to a maximum size).
Since I can't take a screenshot to demonstrate the issue, the best I can do is describe it. It appears as if the border in certain areas is drawn at the wrong size (as in, part of the right edge is being drawn in the middle of the popover; NOT that the border itself is too wide, but rather that the area the border should be bordering is wrong). The area along the actual edge is still there, but is lacking it's layer effects (I have the backgroundView using a border and rounded corner layer effect to give it a nice rounded white edge, emulating the same appearance as the default background view, just a different color). Removing the layer effects does not prevent the issue though. Sometimes it's only a part of the right edge which is drawn incorrectly, sometimes part of the bottom edge is also affected. I can't seem to find any correlation as to when or how this happens (though it is frequent), nor to which edge is affected (though I've never seen it affect the top or left edge).
Does it only happen in the simulator or also on a real device?
This specifically seems to only happen when the popover contains a scrollview/tableview which is larger than the popover (i.e. it is scrollable)
Do you resize the scrollview / tableview in this case? Try adding a UIView inside your UIPopView that would be the container.

How to make gallary view at bottom in blackberry

The nexGTv – Mobile TV for touch phone app has a scrolling horizontal field manager that I want to create in my own app.
It has image buttons at the bottom of the screen, horizontally. These images slide to the right and to left. The initial focus is the horizonal center image, then each image has 10 pixels of padding to the next image. What should i use for this?
I can understand your question, but i can not give you related code but i can tell you the logic behind this. To do this you first set a image at center and set bottom padding 10 pixel then fill images left side and right side. You have to do this in paint method. If you are a Blackberry Developer then you can understand it and try to do it. All the work perform in paint method, by using loops you can do this. This work con not be done by Picture-Scroll-Field because you want middle image with extra padding.

Fade UIImageView as it approaches the edges of a UIScrollView

I have a UIScrollView over an image at the bottom of my app that acts as a dock with icons that can be scrolled through horizontally. Instead of the harsh edges of the UIScrollView, I would like the icons to fade out for a more aesthetically pleasing look. Being new to iOS development, I don't know if either of these would be valid options:
Create a faded image to use as an overlay on the scrollview so the
icons only appear through the visible portion.
Actually change the
alpha of the images based on their distance from the center (or from
each edge).
I suspect the first idea would be the most simple, but I'd like to throw this out there for any other ideas.
Note: I did see this tutorial, however that technique assumes that the background is a solid color. If I were to do it programatically, I would probably need to fade the individual images.
You can definitely implement something along the lines of #2. It'd be something similar to what the tutorial describes. The alpha transition however won't be as smooth as using the gradient layer mentioned in the tutorial or using an image since the entire icon would have the same alpha. How much discernible the difference is depends on the size of your icons. Smaller icons, very few will be able to tell the difference. Larger icons the difference would be quite clear.
You'd have to implement the
(void)scrollViewDidScroll:(UIScrollView *)scrollView
method in your scroll view's delegate class. This method will get called every time the scroll view changes the location of its content. In this method you can call its subviews and adjust their alphas as required. To optimize it a bit instead of calling the alpha adjustments on all the elements you can just update the subviews which are still partially/completely visible.
EDIT: to figure out which views to adjust you'll use the contentOffset property of the scrollView that gets passed as a parameter in the above method.

Resources