Aleksandar • Vacić

iOS bits and pieces

Allow landscape, only on iPhone 6 or 6 Plus

I sort of already solved this - how to allow certain orientation per view controller, late last year while (surprise!) working on the very same app I’m updating now: Banca currency converter.

However, this is a bit different. iOS 8 brings size classes, deprecates old orientation callbacks and in general tries to move away from dealing with fixed numbers.

Oki, what’s the deal here; iPhone 6 Plus has a system-wide support for operating in landscape mode, including home screen arrangement with the dock on the side. Thus it’s more than expected that our apps should work in landscape on iPhone 6 Plus. Gone are the days when you could get away with just Portrait, since that is the natural way to hold the iPhone (for all but video and games).

Phantom spaces in UILabel’s text

Yesterday, I posted an article about how I apparently found a bug in NSAttributedString, happening only on device. I was wrong. There’s no bug, only me being tired (I posted that article at 4am) and not looking for source of the issue hard enough. Here’s what really happened.

While working on Today extension for Banca, I encountered an issue that killed me at least a day or so of productivity. I have a table cell that looks like this:

Right-hand labels have NSTextAlignmentRight set on them and it worked fairly well during inital spec-ing of the cell and even during entire development in the Simulator. It went downhill as I moved to my iPhone.

How to remove UINavigationBar’s bottom border / shadow in iOS 7

One of the most annoying visual things Apple introduced in iOS 7 is inability to remove the navigation bar shadow image. iOS 7 UI is perfect to create seamless transition between the content and the top of the screen.

The only issue is that darn line at the bottom. There is no property on UINavigationBar to hide it. There is shadowImage which allows you to change it, but can’t remove it – shadowImage = nil is the default which shows their default image. Even changing the shadowImage to 100% transparent image is not enough:

For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

Brilliant. 😕 You can remove the shadow only if you also kill the blur, like this:

1
2
3
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init]
          forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

Can’t help to think this was not properly thought through, but given the hectic schedule Apple engineers had for iOS 7, something had to give. Anw, with no other avenue left, it’s subview walkthrough time.

Problem: UICollectionViewCell redraw during interactive resize of UICollectionView

I’m very close to finishing the next big update of Unitica. Headline feature is that app is now Universal and I’ve built custom container controller that looks like this:

I added background colors to clearly visualize the various child levels; at the top you have my custom split view controller with two child controllers:

  • category collection view controller
  • columns controller

This ColumnsController has two child controllers (orange and yellow) - each an instance of UnitViewController, which is UICollectionViewController subclass. Green and bluish violet are actual collection view cells. Layout is UICollectionViewFlowLayout subclass where I make sure that cells always span the full width of the collection view.
This is the most relevant part of the layout:

1
2
3
4
5
6
7
8
9
10
11
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
  return YES;
}

- (void)prepareLayout {
  CGFloat w = floor(self.collectionView.bounds.size.width);
  CGSize is = self.itemSize;
  is.width = w;
  self.itemSize = is;
  [super prepareLayout];
}

The problem I have is that I want to allow changing the split position between the CategoryController and ColumnsController. You just drag the divider in the middle to set the sizes as you wish. Or you can slide them all the way to the edge and have one of those full screen.

This simply refuses to obey and I’m out of ideas what to try to force a proper redraw. Here’s the video that illustrates the problem.