Prevent autolayout from messing with our manually set frames

This commit is contained in:
Maurice Parker 2019-08-25 20:00:34 -05:00
parent 31715ad4f0
commit a0b11da438
6 changed files with 48 additions and 23 deletions

View File

@ -130,6 +130,7 @@
51E595A6228CC36500FCC42B /* ArticleStatusSyncTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E595A4228CC36500FCC42B /* ArticleStatusSyncTimer.swift */; };
51E595AB228DF94C00FCC42B /* SettingsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51E595AA228DF94C00FCC42B /* SettingsTableViewCell.xib */; };
51E595AD228E1C2100FCC42B /* AddAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E595AC228E1C2100FCC42B /* AddAccountViewController.swift */; };
51EAED96231363EF00A9EEE3 /* NonIntrinsicButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EAED95231363EF00A9EEE3 /* NonIntrinsicButton.swift */; };
51EC114C2149FE3300B296E3 /* FolderTreeMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EC114B2149FE3300B296E3 /* FolderTreeMenu.swift */; };
51EF0F77227716200050506E /* FaviconGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF0F76227716200050506E /* FaviconGenerator.swift */; };
51EF0F79227716380050506E /* ColorHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF0F78227716380050506E /* ColorHash.swift */; };
@ -737,6 +738,7 @@
51E595A4228CC36500FCC42B /* ArticleStatusSyncTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleStatusSyncTimer.swift; sourceTree = "<group>"; };
51E595AA228DF94C00FCC42B /* SettingsTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsTableViewCell.xib; sourceTree = "<group>"; };
51E595AC228E1C2100FCC42B /* AddAccountViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAccountViewController.swift; sourceTree = "<group>"; };
51EAED95231363EF00A9EEE3 /* NonIntrinsicButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicButton.swift; sourceTree = "<group>"; };
51EC114B2149FE3300B296E3 /* FolderTreeMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FolderTreeMenu.swift; path = AddFeed/FolderTreeMenu.swift; sourceTree = "<group>"; };
51EF0F76227716200050506E /* FaviconGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconGenerator.swift; sourceTree = "<group>"; };
51EF0F78227716380050506E /* ColorHash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorHash.swift; sourceTree = "<group>"; };
@ -1113,6 +1115,7 @@
children = (
51F85BFA2275D85000C787DC /* Array-Extensions.swift */,
51F85BF42273625800C787DC /* Bundle-Extensions.swift */,
51EAED95231363EF00A9EEE3 /* NonIntrinsicButton.swift */,
5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */,
5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */,
51C45250226506F400C03939 /* String-Extensions.swift */,
@ -2385,6 +2388,7 @@
51C452A422650A2D00C03939 /* ArticleUtilities.swift in Sources */,
51EF0F79227716380050506E /* ColorHash.swift in Sources */,
5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */,
51EAED96231363EF00A9EEE3 /* NonIntrinsicButton.swift in Sources */,
51C4527B2265091600C03939 /* MasterUnreadIndicatorView.swift in Sources */,
515ADE4022E11FAE006B2460 /* SystemMessageViewController.swift in Sources */,
51F85BF92274AA7B00C787DC /* UIBarButtonItem-Extensions.swift in Sources */,

View File

@ -0,0 +1,20 @@
//
// NonIntrinsicButton.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 8/25/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
import UIKit
class NonIntrinsicButton: UIButton {
// Prevent autolayout from messing around with our frame settings
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
}
}

View File

@ -93,7 +93,7 @@ class MasterFeedTableViewCell : UITableViewCell {
}()
private let faviconImageView: UIImageView = {
return UIImageView(image: AppAssets.feedImage)
return NonIntrinsicImageView(image: AppAssets.feedImage)
}()
private var unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero)
@ -156,7 +156,7 @@ private extension MasterFeedTableViewCell {
func addDisclosureView() {
disclosureButton = UIButton(type: .roundedRect)
disclosureButton = NonIntrinsicButton(type: .roundedRect)
disclosureButton!.tintColor = AppAssets.chevronDisclosureColor
disclosureButton!.addTarget(self, action: #selector(buttonPressed(_:)), for: UIControl.Event.touchUpInside)

View File

@ -52,7 +52,7 @@ struct MasterFeedTableViewCellLayout {
separatorInsets = UIEdgeInsets(top: 0, left: rFavicon.maxX + MasterFeedTableViewCellLayout.imageMarginRight, bottom: 0, right: 0)
// Unread Count
let unreadCountSize = unreadCountView.intrinsicContentSize
let unreadCountSize = unreadCountView.contentSize
let unreadCountIsHidden = unreadCountView.unreadCount < 1
var rUnread = CGRect.zero

View File

@ -31,8 +31,8 @@ class MasterFeedUnreadCountView : UIView {
return unreadCount < 1 ? "" : "\(unreadCount)"
}
private var intrinsicContentSizeIsValid = false
private var _intrinsicContentSize = CGSize.zero
private var contentSizeIsValid = false
private var _contentSize = CGSize.zero
override init(frame: CGRect) {
super.init(frame: frame)
@ -46,26 +46,27 @@ class MasterFeedUnreadCountView : UIView {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
textSizeCache = [Int: CGSize]()
invalidateIntrinsicContentSize()
contentSizeIsValid = false
setNeedsDisplay()
}
override var intrinsicContentSize: CGSize {
if !intrinsicContentSizeIsValid {
var contentSize: CGSize {
if !contentSizeIsValid {
var size = CGSize.zero
if unreadCount > 0 {
size = textSize()
size.width += (padding.left + padding.right)
size.height += (padding.top + padding.bottom)
}
_intrinsicContentSize = size
intrinsicContentSizeIsValid = true
_contentSize = size
contentSizeIsValid = true
}
return _intrinsicContentSize
return _contentSize
}
override func invalidateIntrinsicContentSize() {
intrinsicContentSizeIsValid = false
// Prevent autolayout from messing around with our frame settings
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
}
private func textSize() -> CGSize {

View File

@ -281,16 +281,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
}
// override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
// guard let node = coordinator.nodeFor(indexPath), !(node.representedObject is PseudoFeed) else {
// return nil
// }
// if node.representedObject is Feed {
// return makeFeedContextMenu(indexPath: indexPath, includeDeleteRename: true)
// } else {
// return makeFolderContextMenu(indexPath: indexPath)
// }
// }
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
guard let node = coordinator.nodeFor(indexPath), !(node.representedObject is PseudoFeed) else {
return nil
}
if node.representedObject is Feed {
return makeFeedContextMenu(indexPath: indexPath, includeDeleteRename: true)
} else {
return makeFolderContextMenu(indexPath: indexPath)
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
coordinator.selectFeed(indexPath)