Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPhone SE Visual Bug on Badges #7

Closed
tn-tran opened this issue Aug 10, 2018 · 1 comment
Closed

iPhone SE Visual Bug on Badges #7

tn-tran opened this issue Aug 10, 2018 · 1 comment

Comments

@tn-tran
Copy link

tn-tran commented Aug 10, 2018

On the iPhone SE when you first run the app, the section of Badges on the home tab, some of the badges is cut off. But when you go to the Learn tab and earn some points, this visual bug disappears. Also you cannot navigate through the rest of the badges. You can see this bug again by closing the app and earn a few points.

screen shot 2018-08-09 at 9 37 18 pm

screen shot 2018-08-09 at 9 46 52 pm

@caiozullo
Copy link

I had this problem before. Apparently, when any UIView is instantiated from a nib, it starts with whatever frame was set in the nib (Including reusable UITableViewCell instantiated with dequeueReusableCell – you can test this by printing the frame in awakeFromNib).

So, it works fine on big iPhone simulators because in the storyboard the frame matches the device size. However, the iPhone SE has a smaller screen, so elements end up off bounds.

In a normal view hierarchy, this frame would be fixed in runtime. But UITableView + UICollectionView + Autolayout + Auto sizing cells can be a special case 😄

In HomeDataSource.makeBadges() the cell is instantiated with dequeueReusableCell. At that time, the frame is wrong still (in this case the wrong width will break the layout!). So, when the cell's collection view data source is set via cell.collectionView.dataSource = badgeDataSource, the collection view triggers a reload using the wrong frame!

So later on, when BadgesView is asked to return its intrinsicContentSize, it returns the wrong size because collectionView.collectionViewLayout.collectionViewContentSize was calculated with the wrong width. (Auto layout/UITableView/UICollectionView will cache values and avoid layouts for performance reasons.)

One (hacky?) way to solve it is to set a frame to the cell and trigger a layout before setting the data source.

    /// Shows all the badges the user has earned.
    func makeBadges(in tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "Badges", for: indexPath) as? BadgeTableViewCell else {
            fatalError("Failed to dequeue a BadgeTableViewCell.")
        }
	
	// give it the table frame so the real device width is used (needs to trigger a layoutIfNeeded to layout the subviews)
	cell.frame = tableView.bounds
	cell.layoutIfNeeded()

        cell.collectionView.dataSource = badgeDataSource
        cell.collectionView.delegate = badgeDataSource

	// tell the badgesView to layout again
	cell.badgesView.layoutIfNeeded()
		
        return cell
    }
  • Another way is to override layoutSubviews in the BadgeTableViewCell class and force the collection view and badge view to layout but I think that will have performance issues.

  • And yet another way is not to use auto sizing cells and calculate the frames programmatically.

@tn-tran tn-tran closed this as completed Aug 21, 2018
twostraws pushed a commit that referenced this issue May 4, 2019
twostraws added a commit that referenced this issue May 7, 2019
commit 541f8a2
Author: Paul Hudson <[email protected]>
Date:   Tue May 7 17:31:45 2019 +0100

    Build 8, ready for TestFlight or GM - in theory!

commit 2cc2192
Author: Paul Hudson <[email protected]>
Date:   Tue May 7 17:30:44 2019 +0100

    Updated credits screen to HTML.

commit ec7d234
Author: Paul Hudson <[email protected]>
Date:   Tue May 7 17:30:09 2019 +0100

    Added objc.io logo to sticker pack.

commit e85a5e8
Merge: 8618735 05c9d87
Author: Paul Hudson <[email protected]>
Date:   Tue May 7 17:02:27 2019 +0100

    Merge pull request #120 from wayni208/iPadImproved

    Display Credits in HTML

commit 05c9d87
Author: Wayne Nihart <[email protected]>
Date:   Tue May 7 09:45:10 2019 -0600

    Formatting. Fixes from working copy - Xcode testing

commit a29f833
Author: Wayne Nihart <[email protected]>
Date:   Tue May 7 09:21:27 2019 -0600

    Modified VC

commit 5b68218
Author: Wayne Nihart <[email protected]>
Date:   Tue May 7 08:57:20 2019 -0600

    Add CSS to head

commit cf71655
Author: Wayne Nihart <[email protected]>
Date:   Tue May 7 08:51:46 2019 -0600

    Modified VC's methods and listens for font size changes

    Disables Javascript.

commit a50c8bf
Author: Wayne Nihart <[email protected]>
Date:   Tue May 7 07:53:59 2019 -0600

    Add Credits.html and modify CreditsVC to display it

commit dc4bcde
Author: Wayne Nihart <[email protected]>
Date:   Tue May 7 07:49:57 2019 -0600

    Add Credits.html and modify VC to use it

commit 8618735
Author: Paul Hudson <[email protected]>
Date:   Tue May 7 11:55:49 2019 +0100

    Fix for alerts being too large on iPad when in smallest split screen.

commit 2a96c8d
Author: Paul Hudson <[email protected]>
Date:   Tue May 7 11:54:38 2019 +0100

    Added FIXME for Swift warning; would like to show someone at WWDC and get suggestions.

commit fe94fb8
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:40:59 2019 +0100

    Fixed typo.

commit 9ffeb0f
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:36:54 2019 +0100

    Added a workaround for a bizarre UIKit bug when reading news stories on iPad.

commit dc57a3e
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:21:59 2019 +0100

    Disabled bouncing for the web view, because in the News tab it always allows horizontal bouncing even when it isn't possible.

commit 46648ac
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:03:59 2019 +0100

    Updated Help screen to render text from HTML so we can make links by hand, which fixes a problem where data detectors would cause scroll issues in entirely unrelated text views.

commit f42a4ba
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:01:42 2019 +0100

    Removed some unnecessary code in TappableTextView.

commit 32647e4
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:01:16 2019 +0100

    Removed hard line breaks from Zephyr license in Credits.

commit c52e75e
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 21:00:55 2019 +0100

    Stopped text links from being underlined in HTML.

commit 66be532
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 20:06:59 2019 +0100

    Fixed navigation bar background color in the credits screen.

commit 0a8c8fc
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:58:23 2019 +0100

    Allow someArray.map({...}) where someArray.map {...} was expected.

commit fd549e6
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:35:41 2019 +0100

    Predict The Output now tells users what the answer is when they get it wrong.

commit f2e8b1f
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:25:33 2019 +0100

    Made the text entry box in Predict The Output respond to Dynamic Type.

commit f304130
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:17:26 2019 +0100

    Stop clearing the text color for unknown answers.

commit 0e16929
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:17:10 2019 +0100

    Make Type Checker create more answers.

commit 20b8077
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:12:45 2019 +0100

    Fix indent for Review in the Practice table.

commit 8288242
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:04:31 2019 +0100

    Reduced primary/secondary button height by 8 points.

commit a5878ee
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 19:01:15 2019 +0100

    Corrected typo in Predict The Output.

commit d54e388
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 18:36:47 2019 +0100

    Set contentInsetAdjustmentBehavior earlier in StudyTextView.

commit 4274d16
Merge: ec2f545 0a426c4
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 18:24:52 2019 +0100

    Merge branch 'iPadImproved' of https://github.com/twostraws/Unwrap into iPadImproved

commit ec2f545
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 18:24:05 2019 +0100

    Made Tour text adjust itself with Dynamic Type.

commit a298799
Author: Paul Hudson <[email protected]>
Date:   Mon May 6 18:23:48 2019 +0100

    Clarified a Rearrange The Lines question.

commit 0a426c4
Merge: cef2d0c 39d5bbe
Author: Paul Hudson <[email protected]>
Date:   Sun May 5 23:00:23 2019 +0100

    Merge pull request #119 from wayni208/iPadImproved

    Added logic to display last chapter completion. Added Zephyr to readme.

commit 39d5bbe
Author: Wayne Nihart <[email protected]>
Date:   Sun May 5 11:14:48 2019 -0600

    Revert LearnDataSource. Change title in where-now.json

commit 2c165e4
Author: Wayne Nihart <[email protected]>
Date:   Sun May 5 09:37:26 2019 -0600

    Added logic to display last chapter completion. Added Zephyr to readme.

commit cef2d0c
Author: Paul Hudson <[email protected]>
Date:   Sun May 5 02:22:06 2019 +0100

    Added an extra free coding test to ensure we accept code outside the immediate solution.

commit aaefe0b
Author: Paul Hudson <[email protected]>
Date:   Sun May 5 02:15:49 2019 +0100

    Added support for ranges in parens to Free Coding, e.g. (1...100).

commit d0bd916
Author: Paul Hudson <[email protected]>
Date:   Sun May 5 02:06:55 2019 +0100

    Fixed a bug where 'func a' would cause the free coding regex to hang.

commit b4e6220
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 23:02:26 2019 +0100

    Fixed bad hint.

commit 33c3ca6
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 21:58:35 2019 +0100

    Removed empty line.

commit c1c29ba
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 21:54:00 2019 +0100

    Pulled PortraitSplitViewController out to its own file.

commit 4066e27
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 21:45:21 2019 +0100

    Fixed the iPhone UIKit bug with table view offsets being wrong after learning awards. Also fixed the movie rotation bug where going rotating to landscape during a movie would silently pop the study view controller.

commit a647c25
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 15:30:30 2019 +0100

    Reload only visible parts of the learn table view to avoid a UIKit bug where header titles disappear.

commit c353db7
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 15:18:10 2019 +0100

    More navigation clean ups. Yay, for adaptive layout.

commit 7c62506
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 14:34:01 2019 +0100

    Moved to a didSet for the coordinator to get even better animations.

commit 197fcf6
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 14:19:07 2019 +0100

    Moved most of navigation configure up to init() to avoid bad iPhone animations.

commit 61489b7
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 14:03:34 2019 +0100

    Fixed up the web view.

commit ec94cc5
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 13:44:29 2019 +0100

    Trying a locked activity on iPhone no longer shows the please select screen.

commit 3f9eb34
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 13:13:22 2019 +0100

    Finishing a challenge on iPad now shows the correct detail screen.

commit 36012b0
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 12:43:12 2019 +0100

    Home is now presented modally on iPad.

commit 8e167ba
Merge: fc11e63 db2d5c7
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 12:13:55 2019 +0100

    Merge pull request #118 from justJS/iPadImproved

    iPad split view: Add toolbar to WebViewController and use domain instead of title

commit db2d5c7
Author: Julian <[email protected]>
Date:   Sat May 4 09:33:52 2019 +0800

    Add toolbar to web view controller

commit fc11e63
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 02:26:33 2019 +0100

    Stopped asking for reviews in debug mode.

commit 0ab54f4
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 02:20:56 2019 +0100

    Unbreak the Help button.

commit adf586a
Merge: 1b979e9 79d1c95
Author: Julian <[email protected]>
Date:   Sat May 4 09:14:23 2019 +0800

    Merge branch 'iPadImproved' of https://github.com/justjs/unwrapmarzipan into iPadImproved

commit 1b979e9
Author: Julian <[email protected]>
Date:   Sat May 4 09:13:28 2019 +0800

    Fix bundle ID and team

commit 79d1c95
Merge: 5e830e9 55728d0
Author: Julian Schiavo <[email protected]>
Date:   Sat May 4 09:11:44 2019 +0800

    Merge pull request #8 from twostraws/iPadImproved

    Upstream

commit 55728d0
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 02:09:23 2019 +0100

    Inverted the color on all shareable graphics, because template images dislike being rendered into a CGContext.

commit df2cd74
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 02:08:45 2019 +0100

    Beautified image sharing.

commit 2e93162
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 02:08:26 2019 +0100

    Added tags to sharing posts to allow for tracking.

commit 5e830e9
Author: Julian <[email protected]>
Date:   Sat May 4 08:58:05 2019 +0800

    Add support for back/forward buttons

commit 7a4769a
Merge: 8914420 03482f3
Author: Julian Schiavo <[email protected]>
Date:   Sat May 4 08:46:42 2019 +0800

    Merge pull request #7 from twostraws/iPadImproved

    Upstream

commit 03482f3
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 01:01:46 2019 +0100

    Fixed tiny gaps in video.

commit 6454ff8
Author: Paul Hudson <[email protected]>
Date:   Sat May 4 00:37:09 2019 +0100

    Typo correction.

commit f4b5cf7
Author: Paul Hudson <[email protected]>
Date:   Fri May 3 14:55:12 2019 +0100

    Added some example back and forward icons.

commit 8914420
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 23:43:31 2019 +0100

    Spot the Error now uses disabled button color by default.

commit c642d81
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 23:38:57 2019 +0100

    Switched over to SwiftEntryKit for first run alerts.

commit 65d2b8a
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 23:25:01 2019 +0100

    Switched over to SwiftEntryKit for Activity Locked message.

commit 119ab7d
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 23:14:32 2019 +0100

    Added the world's smallest Easter egg to PleaseSelectViewController.

commit 34366b4
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 23:11:18 2019 +0100

    Forced navigation bars to be opaque.

commit ba954e9
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 23:07:22 2019 +0100

    Split the web view controller into view and view controller, trimmed it down a little and fixed a couple if iPhone glitches, then moved other parts of the app over to using it.

commit fc9efac
Merge: ab164a6 0ba6dd9
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 22:07:23 2019 +0100

    Merge pull request #116 from justJS/iPadImproved

    Improve the news tab and fix some bugs

commit 0ba6dd9
Author: Julian <[email protected]>
Date:   Thu May 2 20:52:07 2019 +0800

    - Fix GlossaryViewController
    - Use new ArticleViewController (WKWebView + reload + share support) instead of SFSafariViewController for the News tab
    - Correct some table view selection

commit 90524ed
Merge: a7d54c6 ab164a6
Author: Julian Schiavo <[email protected]>
Date:   Thu May 2 19:18:57 2019 +0800

    Merge pull request #4 from twostraws/iPadImproved

    Merge upstream

commit ab164a6
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 12:16:24 2019 +0100

    Made the news coordinator behave correctly on iPhone.

commit 016d000
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 12:14:49 2019 +0100

    Fixes iPhone gaps.

commit e17819a
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 12:03:01 2019 +0100

    Inserted possible solution to challenge results always staying visible on iPad.

commit c3e3c43
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 11:39:43 2019 +0100

    Updated Challenges for split view controllers.

commit a080d87
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 11:25:16 2019 +0100

    Split views now implemented on Practice and News. Still needs a lot more work, though.

commit a7d54c6
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 01:40:42 2019 +0100

    Removed whitespace.

commit 4945ee2
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 01:39:47 2019 +0100

    Temporarily made LearnCoordinator the split view controller delegate, to get collapsing working correctly.

commit a3a2810
Author: Paul Hudson <[email protected]>
Date:   Thu May 2 01:14:57 2019 +0100

    First pass at making Learn tab work with adaptive layout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants