Auto Layout

RSS for tag

Create a user interface that dynamically responds to changes in the available screen space using Auto Layout.

Posts under Auto Layout tag

117 Posts

Post

Replies

Boosts

Views

Activity

Display/constraint update cycle crashes in macOS 11/12
I recently migrated to macOS Monterey to build my macOS app. After building the app in 12.3, the users have started to experience mysterious crashes related to view layout. The first one was somehow related to NSScrollView endlessly resizing itself between two width values, and I figured it could have something to do with scroll bar sizing, but found no apparent fix. Crashing on exception: The window has been marked as needing another Display Window pass, but it has already had more Display Window passes than there are views in the window. I circumvented the issue with some duct tape, but ended up with another layout exception on other users' systems: Crashing on exception: The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window. It's very hard to debug this, because the bug seems to be very system-specific. However, by intense googling, I've seen that Safari and Xcode have also suffered from the exact same crash, but I've found no information on how they might have been fixed. I'm starting to suspect that there is something principal that has been changed within view layout routines macOS 11/12 that I'm completely missing. Does anyone have any experience with such issues, and how to start digging deeper?
4
0
2.6k
Apr ’22
Impossible to set up layout with view hierarchy unprepared for constraint.
After upgrading to ios15, there are many crashes. What is the reason?? -[UIView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 468 -[UIView _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 212 -[UIView(UIConstraintBasedLayout) nsli_addConstraint:]  -[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke + 176 0x000000019b069000 + 34296 -[UIView(UIConstraintBasedLayout) addConstraints:] + 196 -[UIInputWindowControllerHostingItem updateVisibilityConstraintsForPlacement:] + 440 -[UIInputWindowControllerHostingItem updateViewConstraints] + 6888 -[UIInputWindowControllerHosting updateViewConstraints] + -[UIInputWindowController updateViewConstraints] + 92 -[UIInputWindowController changeToInputViewSet:] + 2252 ___43-[UIInputWindowController setInputViewSet:]_block_invoke.1285 + 40 ___77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.1042 + 1600 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 724 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 248 -[UIViewAnimationState animationDidStop:finished:] + 244 0x00000001861eb000 + 821768 libdispatch.dylib __dispatch_client_callout + 20
2
0
926
Mar ’22
"on screen"-homebutton overlaps layout of our app
Hello, I m one of the developers of the My CM app team (Belgian Health Insurance company). While testing on apple devices that have no physical homebutton, but the on-screen "black bar" we notice some strange behaviour. See picture attached. The phone on the left is a iPhone 13 Pro Max, the one on the right is an iPhone XR. Both have ios 15.2. Both phones have the same build of our app. On the Pro Max the black bar is on top of our layout, on the XR our layout seems to be pushed up a bit. The desired behaviour is the behaviour on the XR. Can somebody give us advice on how to handle this issue? Kind regards, Lode
1
0
721
Mar ’22
Undocumented 'NSViewActuallyUpdateFromLayoutEngine' call adds width when light/dark mode changes
This is a fairly bizarre behavior and I wonder if anyone with deep knowledge of NSView layout internals has a clue. I have a view that hosts a number of toolbar-like buttons, some subclasses of NSButton and other subclasses of NSPopUpButton. The latter are used in pull-down mode and do not display a title (just a pull-down indicator and icon), they are similar in size and appearance to the NSButtons. When the app is switched between light mode and dark mode, some layout action is triggered which always adds 5 pixels of widths to the pull-down buttons. When I override setFrame and set a breakpoint, this is happening below NNAApplication nextEventMatchingMask in an undocumented function called NSViewActuallyUpdateFromLayoutEngine. This method always adds 5 pixels to width for repeated light/dark mode changes. It does so on a pull-down even if it has already done so before, so these controls just keep growing, and this does not seem to be related to any obvious intrinsic content. Some things I would note in trying to track it down: It only happens to the popup buttons, not the regular NSButtons in the same superviews I have some of these in a horizontal stack view and some positioned statically in a regular NSView - both scenarios get this 5-pixel-width-resize I've tried overriding both instrinsicContentSize and fittingSize to return the current frame size, as a way to tell the layout system not to change the size, and that didn't work There are no explicit constraints created for these views; they are created in code not in Interface Builder I've tried using the autolayout mask value NSViewNotSizable with the translates flag set to YES, that does not prevent the issue I've tried setting the superview autoresizesSubviews flag to false and also making sure translates flags were false to not create unwanted constraints, these also do not prevent the issue The only code values I had related to 5 pixels were a spacing setting and a left inset on the horizontal stack view - so I removed those as a check, but as I'd expect that did not change the behavior The only way I've been able to defeat it is to add a .sizeLocked property to my subclass and, if set, replace the incoming frame.size with the current one to prevent the resize while still allowing origin to change. Obviously that's not ideal but as a brute-force workaround it works for this specific issue. However I'm seeing other weird layout creep as well on repeated light/dark change. I wonder why this happens, and what the correct fix might be! Why is dark/light mode switching resizing anything in layout, when the size of windows and views have not changed?
1
0
931
Mar ’22
NSTextView in NSScrollView with magnification crashes on resize
I have an NSTextView inside an NSScrollView with magnification. Zooming in with a pinch-and-zoom gesture works fine, but if I then resize the window while zoomed in, it will eventually crash with the error The window has been marked as needing another Display Window pass, but it has already had more Display Window passes than there are views in the window. It does not always happen immediately, sometimes you have to keep resizing for a while to trigger it. I have made a video illustrating the problem here: youtu.be/M_JRQI2oDaY The original code is here: https://github.com/angstsmurf/spatterlight/tree/helpviewtest (The branch helpviewtest is a cut down test case created for this problem.)
1
0
1.5k
Mar ’22
Autolayout warning "NSLayoutConstraint is being configured with a constant that exceeds internal limits"
I have a subclass of UIScrollView called MyScrollView. There is a subview called contentViewinside MyScrollView. The width constraint is set to be the contentSize of MyScrollView. private func setupSubviews() { contentView = ContentView() contentView.backgroundColor = UIColor.blue contentView.translatesAutoresizingMaskIntoConstraints = false contentView.isUserInteractionEnabled = true self.addSubview(contentView) contentView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true contentView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true contentView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true contentView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true // create contentView's Width and Height constraints cvWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: 0.0) cvHeightConstraint = contentView.heightAnchor.constraint(equalToConstant: 0.0) // activate them cvWidthConstraint.isActive = true cvHeightConstraint.isActive = true cvWidthConstraint.constant = myWidthConstant //<--- problem here if myWidthConstant is very high, such as 512000 cvHeightConstraint.constant = frame.height contentView.layoutIfNeeded() } The problem is if I set cvWidthConstraint.constant to a very high value such as 521000, I get a warning: This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on BOOL _NSLayoutConstraintNumberExceedsLimit(void) to debug. This will be logged only once. This may break in the future. I wonder how does one set UIScrollView content size to be very high values?
1
0
1.2k
Mar ’22
iPadOS 15 Safe Area not working with Multitasking Control Button
The multitasking control button is getting in the way of my pre-existing button and I would like to alter the position conditionally, right below the multitasking button. Since the status bar is not supported in any of my app's view controllers using Safe Area Guide Insets is not an option. Is there a way to determine whether the Multitasking Control Button is visible besides checking the os version of the device?
1
0
751
Jan ’22
Safe area is not updated after UIViewController.viewWillDisappear is called
To me it looks like the safe area of a view is not updated after the owning view controller's .viewWillDisappear() method is called. Is this intended or a bug in the framework? The issue is easily visualised by creating a custom UIViewControllerTransitioningDelegate that animates a smaller view in one view controller, to full screen size in another (constrained to safe areas). Then the safe areas will expand as the present animation goes on (as expected), but will not shrink as the dismiss animation goes on (not expected!). The expected behaviour would be that the safe area expands during the present animation, and shrinks during the dismiss animation. The gif below shows the unexpected behaviour. The grey area of the presented view controller is the safe area. I've attached the code I used to visualise this problem. ViewController.swift presents MyViewController.swift using FullScreenTransitionManager.swift FullScreenTransitionManager.swift MyViewController.swift ViewController.swift
1
0
2.9k
Dec ’21
NSTableView (view-based) with auto layout grows, but does not shrink rows
I have a NSTableView in view-based (not cell-based) mode with usesAutomaticRowHeights=YES. The rows have dynamic height that might change interactively at any time. This setup successfully grows table view rows (row content is never clipped). But unfortunately, table view rows don't shrink to the intrinsic row view height, when row views get shorter. Calling noteHeightOfRowsWithIndexesChanged: on the table view after layout does not seem to fix the problem, my tableView:heightOfRow: is also not called again after noteHeightOfRowsWithIndexesChanged:. Is there anything I have missed/isn't documented about using auto layout in NSView-based tableviews with variable row height? After all, growing rows works out of the box without any additional code, they just do not shrink on their own to fit the row view. Thanks in advance for any feedback!
2
0
1.6k
Dec ’21
Swift dynamic uilabel size
Hey I am desperate how I can make my app looks good for all end devices. I have e.g. a completely normal label with the text "Start" and the size UIFont (name: "Arial", size: 35). It also looks good on an Iphone 12 pro max, but the text on an iphone se is simply way too big. How do I get it to look good? And why can't apple adjust the size itself? I would be very happy to hear from you. Best regards
1
0
3.7k
Dec ’21
iPhone with iOS 14 beta 2 doesn't autorotate when connected to XCode debugger
I have iPhone 11 Pro running iOS 14 beta 2. In one of my projects (and only that project perhaps), the view controller doesn't autorotate when connected to XCode (11 or 12) debugger. When not connected to debugger, there is no issue in autorotation. This happens for only one particular project and it's not clear what could be blocking autorotation. None of the autorotation methods are called. I wonder what could be blocking autorotation. And if I connect any iOS 13 device, autorotation works with the debugger. Is this a known issue with iOS 14/XCode?
12
0
5.5k
Dec ’21
Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES Xcode 13
Hello! I have updated my project to Xcode 13 and iOS 15. Now the app is crashing with an error related to autoresizing masks in UITableViewCells. I have tried to change UITableViewCells Layer property in the inspector to Inferred and followed this post, but none of them are working. Have you encountered this problem. How it could be fixed? Thanks 🙏
5
0
3.5k
Dec ’21
UITextView's text (or attributedText) is erasing right after ViewController was dismissing modally
There are two problems which have an one root. I present ViewController modally and it has UITextView in ScrollView, when I call dismiss it, right after that, the text on UITextView is erasing This bug affects on following solution, describing here https://stackoverflow.com/questions/50011682/handling-scroll-views-with-custom-interactive-view-controller-presentation-an And If I uncomment following code, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I unthouch screen, the text will be shown on screen. class ChildViewController: UIViewController {     private let descriptionTextView: UITextView = {         let tv = UITextView()         tv.font = .systemFont(ofSize: 15)         tv.isSelectable = true         tv.textContainer.lineFragmentPadding = .zero         tv.textContainerInset = .zero         tv.isEditable = false         tv.isScrollEnabled = false         tv.isUserInteractionEnabled = true         tv.dataDetectorTypes = .link         tv.bounces = false         tv.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         tv.text = "There are two view controllers: ViewController and TextViewController. Both view controllers are showing a UITextView and a button. I've created a segue called \"textSegue\" when I press the \"Text\" button on the ViewController the text is passed to the TextViewController and displayed. On the TextViewController I can select the text and press the 'Bold' button to make the text bold. When I press the \"Back\" button, the TextViewController is dismissed and the ViewController will show the attributed text. The problem is, when I press the \"Text\" button again and the TextViewController shows, the text in the UITextView doesn't show the attributed text (it is'n bold anymore)."         tv.translatesAutoresizingMaskIntoConstraints = false         return tv     }()     private lazy var scrollView: UIScrollView = {         let scrollView = UIScrollView()         scrollView.bounces = false         scrollView.translatesAutoresizingMaskIntoConstraints = false         scrollView.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         return scrollView     }()     override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         view.layer.cornerRadius = 24         view.addSubview(scrollView)         scrollView.addSubview(descriptionTextView)         addDismissButton()         NSLayoutConstraint.activate([             scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 24),             scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),             scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),             scrollView.rightAnchor.constraint(equalTo: view.rightAnchor),             descriptionTextView.topAnchor.constraint(equalTo: scrollView.topAnchor),            descriptionTextView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),             descriptionTextView.leftAnchor.constraint(equalTo: scrollView.leftAnchor),             descriptionTextView.rightAnchor.constraint(equalTo: scrollView.rightAnchor),             descriptionTextView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),         ])     }     private func addDismissButton() {         let button = UIButton(type: .system)         button.setTitle("Dismiss", for: .normal)         button.addTarget(self, action: #selector(dismissSelf), for: .touchUpInside)         view.addSubview(button)         button.translatesAutoresizingMaskIntoConstraints = false         NSLayoutConstraint.activate([             button.centerXAnchor.constraint(equalTo: view.centerXAnchor),             button.bottomAnchor.constraint(equalTo: view.bottomAnchor),             button.widthAnchor.constraint(equalToConstant: 200),             button.heightAnchor.constraint(equalToConstant: 80),             ])     }         @objc func dismissSelf() {         self.dismiss(animated: true)     } } class ParentViewController: UIViewController {     private let transition = PanelTransition()     @IBAction func openDidPress(_ sender: Any) {         let child = ChildViewController() //        child.transitioningDelegate = transition //        child.modalPresentationStyle = .custom         child.modalPresentationStyle = .fullScreen                present(child, animated: true)     } } And If I uncomment following code child.transitioningDelegate = transition child.modalPresentationStyle = .custom, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I untouch the screen, the text will be shown on screen. And I could catch this on View Debuger, and text is existing in UITextView, but on screen is not. Is It bug on UITextView?
6
0
1.7k
Nov ’21
Auto-hide an iOS app following a user action
We have an application developed by one of our technology partners, to run with same behavior on both iOS and Android as an Authenticator mean used as one (out of 2) factor of authentication for PSD2 payments in Europe. The concept is that whenever the user is doing some action using a certain PSD2 compatible payment application (either from his mobile or thru the web) that needs to undergo a Strong Customer Authentication, he needs to authenticate himself using 2 factors, one of which is that he receives a push notification on his phone device hosting the said Authenticator app. When the push notification is pressed, the authenticator application appears on mobile screen with a message containing details about the PSD2 payment action being done (merchant name, amount, etc..). The user needs to press one of 2 buttons "Approve" or "Decline". Once he presses any one of these, the Authenticator application submits the response to its backend, and it should "automatically disappear" from the mobile screen once it informs its backend about the user's action (Approve or Decline); i.e. after the user presses one of the buttons, the Authenticator app should disappear in 1-2 seconds. We are not concerned how it disappears i.e. if the application closes itself (exiting), goes to background, suspend itself or any other method of hiding from display. The important is that the previous 3rd party payment application if running from same mobile device, it should be unveiled and re-appears on screen without any further action from the user. This is a mandate in PSD2 regulation. With Android we have no issue. With iOS, our vendor who developed the Authenticator app, says that Apple inhibits the automated disappearance of an iOS compatible application and that Apple will reject the app when it is submitted for review in case it does some sort of automatic exiting. From my readings, it seems yes Apple does not certify an auto-exit of an iOS app, however as said above, we just need to hide (with whatever way) the Authenticator automatically and unveil the 3rd party payment app (which can be any PSD2 compatible app for which we do not have any control to solicit it to bring itself to the foreground). Kindly advise on a solution. Thanks and regards,
2
0
774
Nov ’21
Creating square views regardless of orientation
I am trying to create a UIView within a UIStackView that I want to always be square regardless of device and orientation. I have seen posting that explain how others have done it (setting constraints between UIView and superview for both height and width - a required set and an optional set - along with a 1:1 aspect constraint for the UIView) , but it no longer seems to work under all instances - in particular iPad and iPhone 11s. Does anyone have any advice on how to make this happen. It seems to me to be a pretty routine thing to do. I've done it before programmatically, but I would really like to get it done within Interface Builder. Any suggestions would be greatly appreciated.
1
0
2.0k
Nov ’21
Why does NSStackView prevent resizing of parent view/window?
I'm implementing a horizontal NSStackView with child views of varying size. The stack view should resize horizontally with its parent view, which in turn resizes with the window. I expect the stack view's arranged distribution (fill proportionally) to adjust the distribution of child views as its width changes. I keep hitting the bizarre behavior where the window can't be resized horizontally at all - the vertical/diagonal resize cursors no longer appear, and the window can only be resized vertically. The problem is not that the child view doesn't resize with the window: the child view actually prevents resizing of the window! I first saw this creating an empty NSStackView and adding it to its parent view in code, with layout constraints (top, leading, trailing; also tried width). I tried messing with constraint priorities but that did not correct the issue. (With the stack view not there, its parent view resizes with the window just fine). When I created the NSStackView in the .xib this problem went away, the empty NSStackView resizes horizontally along with its parent, so that's what I'm doing now. However, now when I add a set of arranged subviews in code, it happens again - they are distributed perfectly, but the window again cannot be horizontally resized! The subviews are minimal NSView implementations (drawing their bounds); they do not have intrinsic size. They do each have child NSTextField labels, with autolayout constraints to horizontally resize along with their parents. There are no constraints besides those internal to each child view and its label subview. What am I not understanding about AutoLayout and NSStackView? I cannot imagine an intentional design that would break the user's ability to resize the window in one direction based on anything an NSStackView does, but that's exactly what happens.
1
0
2.4k
Oct ’21
Resize image with autolayout
My app loads an image at runtime and I want to display it inside a table cell. To do that I created a UIView (trailing/leading/top/bottom: 10) inside the cell and added a UIImageView as its child. What constraints do I need for the child, so the image keeps its proper aspect ration, isn't wider than the width of the screen and there's no unused space (apart from the constraints)? I tried to use: Trailing/leading/top/bottom: 0 Align center x/y This works if the image uses the portrait format but with landscape there's unused space above and below the image. I also tried to set the view's height to ">=50" but no success and I can't just set a max. value because my app has to work on both iPhones and iPads.
2
0
1.5k
Oct ’21
Ambiguous layout warnings after Xcode 13.0 upgrade
Hi. My 2 years old project shows ambiguous layout warnings after installing Xcode 13.0. The warnings are basically nuisance (layout shows correctly in the app). All the warnings refer to constraints of objects inside a tableview. The warnings start only after cell 16 downwards (distributed across 4 sections, S1: 2 cells, S2: 2 cells, S3: 1 cells, S4: 12 cells, ...). Hence my idea, if there is any limit to the number of cells Xcode 13.0 can handle? Previous Xcode didn't have any (!) issues regarding this portion of the layout. The screenshots just show an example of such a nuisance warning. Any ideas? Thanks.
2
0
1k
Oct ’21
Display/constraint update cycle crashes in macOS 11/12
I recently migrated to macOS Monterey to build my macOS app. After building the app in 12.3, the users have started to experience mysterious crashes related to view layout. The first one was somehow related to NSScrollView endlessly resizing itself between two width values, and I figured it could have something to do with scroll bar sizing, but found no apparent fix. Crashing on exception: The window has been marked as needing another Display Window pass, but it has already had more Display Window passes than there are views in the window. I circumvented the issue with some duct tape, but ended up with another layout exception on other users' systems: Crashing on exception: The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window. It's very hard to debug this, because the bug seems to be very system-specific. However, by intense googling, I've seen that Safari and Xcode have also suffered from the exact same crash, but I've found no information on how they might have been fixed. I'm starting to suspect that there is something principal that has been changed within view layout routines macOS 11/12 that I'm completely missing. Does anyone have any experience with such issues, and how to start digging deeper?
Replies
4
Boosts
0
Views
2.6k
Activity
Apr ’22
Mixed Orientations
Is it possible to program specific screens to only do landscape OR portrait mode, in the same application on iPhone. Any insight would be appreciated.
Replies
1
Boosts
0
Views
530
Activity
Apr ’22
Impossible to set up layout with view hierarchy unprepared for constraint.
After upgrading to ios15, there are many crashes. What is the reason?? -[UIView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 468 -[UIView _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 212 -[UIView(UIConstraintBasedLayout) nsli_addConstraint:]  -[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke + 176 0x000000019b069000 + 34296 -[UIView(UIConstraintBasedLayout) addConstraints:] + 196 -[UIInputWindowControllerHostingItem updateVisibilityConstraintsForPlacement:] + 440 -[UIInputWindowControllerHostingItem updateViewConstraints] + 6888 -[UIInputWindowControllerHosting updateViewConstraints] + -[UIInputWindowController updateViewConstraints] + 92 -[UIInputWindowController changeToInputViewSet:] + 2252 ___43-[UIInputWindowController setInputViewSet:]_block_invoke.1285 + 40 ___77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.1042 + 1600 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 724 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 248 -[UIViewAnimationState animationDidStop:finished:] + 244 0x00000001861eb000 + 821768 libdispatch.dylib __dispatch_client_callout + 20
Replies
2
Boosts
0
Views
926
Activity
Mar ’22
"on screen"-homebutton overlaps layout of our app
Hello, I m one of the developers of the My CM app team (Belgian Health Insurance company). While testing on apple devices that have no physical homebutton, but the on-screen "black bar" we notice some strange behaviour. See picture attached. The phone on the left is a iPhone 13 Pro Max, the one on the right is an iPhone XR. Both have ios 15.2. Both phones have the same build of our app. On the Pro Max the black bar is on top of our layout, on the XR our layout seems to be pushed up a bit. The desired behaviour is the behaviour on the XR. Can somebody give us advice on how to handle this issue? Kind regards, Lode
Replies
1
Boosts
0
Views
721
Activity
Mar ’22
Undocumented 'NSViewActuallyUpdateFromLayoutEngine' call adds width when light/dark mode changes
This is a fairly bizarre behavior and I wonder if anyone with deep knowledge of NSView layout internals has a clue. I have a view that hosts a number of toolbar-like buttons, some subclasses of NSButton and other subclasses of NSPopUpButton. The latter are used in pull-down mode and do not display a title (just a pull-down indicator and icon), they are similar in size and appearance to the NSButtons. When the app is switched between light mode and dark mode, some layout action is triggered which always adds 5 pixels of widths to the pull-down buttons. When I override setFrame and set a breakpoint, this is happening below NNAApplication nextEventMatchingMask in an undocumented function called NSViewActuallyUpdateFromLayoutEngine. This method always adds 5 pixels to width for repeated light/dark mode changes. It does so on a pull-down even if it has already done so before, so these controls just keep growing, and this does not seem to be related to any obvious intrinsic content. Some things I would note in trying to track it down: It only happens to the popup buttons, not the regular NSButtons in the same superviews I have some of these in a horizontal stack view and some positioned statically in a regular NSView - both scenarios get this 5-pixel-width-resize I've tried overriding both instrinsicContentSize and fittingSize to return the current frame size, as a way to tell the layout system not to change the size, and that didn't work There are no explicit constraints created for these views; they are created in code not in Interface Builder I've tried using the autolayout mask value NSViewNotSizable with the translates flag set to YES, that does not prevent the issue I've tried setting the superview autoresizesSubviews flag to false and also making sure translates flags were false to not create unwanted constraints, these also do not prevent the issue The only code values I had related to 5 pixels were a spacing setting and a left inset on the horizontal stack view - so I removed those as a check, but as I'd expect that did not change the behavior The only way I've been able to defeat it is to add a .sizeLocked property to my subclass and, if set, replace the incoming frame.size with the current one to prevent the resize while still allowing origin to change. Obviously that's not ideal but as a brute-force workaround it works for this specific issue. However I'm seeing other weird layout creep as well on repeated light/dark change. I wonder why this happens, and what the correct fix might be! Why is dark/light mode switching resizing anything in layout, when the size of windows and views have not changed?
Replies
1
Boosts
0
Views
931
Activity
Mar ’22
NSTextView in NSScrollView with magnification crashes on resize
I have an NSTextView inside an NSScrollView with magnification. Zooming in with a pinch-and-zoom gesture works fine, but if I then resize the window while zoomed in, it will eventually crash with the error The window has been marked as needing another Display Window pass, but it has already had more Display Window passes than there are views in the window. It does not always happen immediately, sometimes you have to keep resizing for a while to trigger it. I have made a video illustrating the problem here: youtu.be/M_JRQI2oDaY The original code is here: https://github.com/angstsmurf/spatterlight/tree/helpviewtest (The branch helpviewtest is a cut down test case created for this problem.)
Replies
1
Boosts
0
Views
1.5k
Activity
Mar ’22
Autolayout warning "NSLayoutConstraint is being configured with a constant that exceeds internal limits"
I have a subclass of UIScrollView called MyScrollView. There is a subview called contentViewinside MyScrollView. The width constraint is set to be the contentSize of MyScrollView. private func setupSubviews() { contentView = ContentView() contentView.backgroundColor = UIColor.blue contentView.translatesAutoresizingMaskIntoConstraints = false contentView.isUserInteractionEnabled = true self.addSubview(contentView) contentView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true contentView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true contentView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true contentView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true // create contentView's Width and Height constraints cvWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: 0.0) cvHeightConstraint = contentView.heightAnchor.constraint(equalToConstant: 0.0) // activate them cvWidthConstraint.isActive = true cvHeightConstraint.isActive = true cvWidthConstraint.constant = myWidthConstant //<--- problem here if myWidthConstant is very high, such as 512000 cvHeightConstraint.constant = frame.height contentView.layoutIfNeeded() } The problem is if I set cvWidthConstraint.constant to a very high value such as 521000, I get a warning: This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on BOOL _NSLayoutConstraintNumberExceedsLimit(void) to debug. This will be logged only once. This may break in the future. I wonder how does one set UIScrollView content size to be very high values?
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’22
iPadOS 15 Safe Area not working with Multitasking Control Button
The multitasking control button is getting in the way of my pre-existing button and I would like to alter the position conditionally, right below the multitasking button. Since the status bar is not supported in any of my app's view controllers using Safe Area Guide Insets is not an option. Is there a way to determine whether the Multitasking Control Button is visible besides checking the os version of the device?
Replies
1
Boosts
0
Views
751
Activity
Jan ’22
Safe area is not updated after UIViewController.viewWillDisappear is called
To me it looks like the safe area of a view is not updated after the owning view controller's .viewWillDisappear() method is called. Is this intended or a bug in the framework? The issue is easily visualised by creating a custom UIViewControllerTransitioningDelegate that animates a smaller view in one view controller, to full screen size in another (constrained to safe areas). Then the safe areas will expand as the present animation goes on (as expected), but will not shrink as the dismiss animation goes on (not expected!). The expected behaviour would be that the safe area expands during the present animation, and shrinks during the dismiss animation. The gif below shows the unexpected behaviour. The grey area of the presented view controller is the safe area. I've attached the code I used to visualise this problem. ViewController.swift presents MyViewController.swift using FullScreenTransitionManager.swift FullScreenTransitionManager.swift MyViewController.swift ViewController.swift
Replies
1
Boosts
0
Views
2.9k
Activity
Dec ’21
NSTableView (view-based) with auto layout grows, but does not shrink rows
I have a NSTableView in view-based (not cell-based) mode with usesAutomaticRowHeights=YES. The rows have dynamic height that might change interactively at any time. This setup successfully grows table view rows (row content is never clipped). But unfortunately, table view rows don't shrink to the intrinsic row view height, when row views get shorter. Calling noteHeightOfRowsWithIndexesChanged: on the table view after layout does not seem to fix the problem, my tableView:heightOfRow: is also not called again after noteHeightOfRowsWithIndexesChanged:. Is there anything I have missed/isn't documented about using auto layout in NSView-based tableviews with variable row height? After all, growing rows works out of the box without any additional code, they just do not shrink on their own to fit the row view. Thanks in advance for any feedback!
Replies
2
Boosts
0
Views
1.6k
Activity
Dec ’21
Swift dynamic uilabel size
Hey I am desperate how I can make my app looks good for all end devices. I have e.g. a completely normal label with the text "Start" and the size UIFont (name: "Arial", size: 35). It also looks good on an Iphone 12 pro max, but the text on an iphone se is simply way too big. How do I get it to look good? And why can't apple adjust the size itself? I would be very happy to hear from you. Best regards
Replies
1
Boosts
0
Views
3.7k
Activity
Dec ’21
iPhone with iOS 14 beta 2 doesn't autorotate when connected to XCode debugger
I have iPhone 11 Pro running iOS 14 beta 2. In one of my projects (and only that project perhaps), the view controller doesn't autorotate when connected to XCode (11 or 12) debugger. When not connected to debugger, there is no issue in autorotation. This happens for only one particular project and it's not clear what could be blocking autorotation. None of the autorotation methods are called. I wonder what could be blocking autorotation. And if I connect any iOS 13 device, autorotation works with the debugger. Is this a known issue with iOS 14/XCode?
Replies
12
Boosts
0
Views
5.5k
Activity
Dec ’21
Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES Xcode 13
Hello! I have updated my project to Xcode 13 and iOS 15. Now the app is crashing with an error related to autoresizing masks in UITableViewCells. I have tried to change UITableViewCells Layer property in the inspector to Inferred and followed this post, but none of them are working. Have you encountered this problem. How it could be fixed? Thanks 🙏
Replies
5
Boosts
0
Views
3.5k
Activity
Dec ’21
UITextView's text (or attributedText) is erasing right after ViewController was dismissing modally
There are two problems which have an one root. I present ViewController modally and it has UITextView in ScrollView, when I call dismiss it, right after that, the text on UITextView is erasing This bug affects on following solution, describing here https://stackoverflow.com/questions/50011682/handling-scroll-views-with-custom-interactive-view-controller-presentation-an And If I uncomment following code, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I unthouch screen, the text will be shown on screen. class ChildViewController: UIViewController {     private let descriptionTextView: UITextView = {         let tv = UITextView()         tv.font = .systemFont(ofSize: 15)         tv.isSelectable = true         tv.textContainer.lineFragmentPadding = .zero         tv.textContainerInset = .zero         tv.isEditable = false         tv.isScrollEnabled = false         tv.isUserInteractionEnabled = true         tv.dataDetectorTypes = .link         tv.bounces = false         tv.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         tv.text = "There are two view controllers: ViewController and TextViewController. Both view controllers are showing a UITextView and a button. I've created a segue called \"textSegue\" when I press the \"Text\" button on the ViewController the text is passed to the TextViewController and displayed. On the TextViewController I can select the text and press the 'Bold' button to make the text bold. When I press the \"Back\" button, the TextViewController is dismissed and the ViewController will show the attributed text. The problem is, when I press the \"Text\" button again and the TextViewController shows, the text in the UITextView doesn't show the attributed text (it is'n bold anymore)."         tv.translatesAutoresizingMaskIntoConstraints = false         return tv     }()     private lazy var scrollView: UIScrollView = {         let scrollView = UIScrollView()         scrollView.bounces = false         scrollView.translatesAutoresizingMaskIntoConstraints = false         scrollView.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         return scrollView     }()     override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         view.layer.cornerRadius = 24         view.addSubview(scrollView)         scrollView.addSubview(descriptionTextView)         addDismissButton()         NSLayoutConstraint.activate([             scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 24),             scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),             scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),             scrollView.rightAnchor.constraint(equalTo: view.rightAnchor),             descriptionTextView.topAnchor.constraint(equalTo: scrollView.topAnchor),            descriptionTextView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),             descriptionTextView.leftAnchor.constraint(equalTo: scrollView.leftAnchor),             descriptionTextView.rightAnchor.constraint(equalTo: scrollView.rightAnchor),             descriptionTextView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),         ])     }     private func addDismissButton() {         let button = UIButton(type: .system)         button.setTitle("Dismiss", for: .normal)         button.addTarget(self, action: #selector(dismissSelf), for: .touchUpInside)         view.addSubview(button)         button.translatesAutoresizingMaskIntoConstraints = false         NSLayoutConstraint.activate([             button.centerXAnchor.constraint(equalTo: view.centerXAnchor),             button.bottomAnchor.constraint(equalTo: view.bottomAnchor),             button.widthAnchor.constraint(equalToConstant: 200),             button.heightAnchor.constraint(equalToConstant: 80),             ])     }         @objc func dismissSelf() {         self.dismiss(animated: true)     } } class ParentViewController: UIViewController {     private let transition = PanelTransition()     @IBAction func openDidPress(_ sender: Any) {         let child = ChildViewController() //        child.transitioningDelegate = transition //        child.modalPresentationStyle = .custom         child.modalPresentationStyle = .fullScreen                present(child, animated: true)     } } And If I uncomment following code child.transitioningDelegate = transition child.modalPresentationStyle = .custom, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I untouch the screen, the text will be shown on screen. And I could catch this on View Debuger, and text is existing in UITextView, but on screen is not. Is It bug on UITextView?
Replies
6
Boosts
0
Views
1.7k
Activity
Nov ’21
Auto-hide an iOS app following a user action
We have an application developed by one of our technology partners, to run with same behavior on both iOS and Android as an Authenticator mean used as one (out of 2) factor of authentication for PSD2 payments in Europe. The concept is that whenever the user is doing some action using a certain PSD2 compatible payment application (either from his mobile or thru the web) that needs to undergo a Strong Customer Authentication, he needs to authenticate himself using 2 factors, one of which is that he receives a push notification on his phone device hosting the said Authenticator app. When the push notification is pressed, the authenticator application appears on mobile screen with a message containing details about the PSD2 payment action being done (merchant name, amount, etc..). The user needs to press one of 2 buttons "Approve" or "Decline". Once he presses any one of these, the Authenticator application submits the response to its backend, and it should "automatically disappear" from the mobile screen once it informs its backend about the user's action (Approve or Decline); i.e. after the user presses one of the buttons, the Authenticator app should disappear in 1-2 seconds. We are not concerned how it disappears i.e. if the application closes itself (exiting), goes to background, suspend itself or any other method of hiding from display. The important is that the previous 3rd party payment application if running from same mobile device, it should be unveiled and re-appears on screen without any further action from the user. This is a mandate in PSD2 regulation. With Android we have no issue. With iOS, our vendor who developed the Authenticator app, says that Apple inhibits the automated disappearance of an iOS compatible application and that Apple will reject the app when it is submitted for review in case it does some sort of automatic exiting. From my readings, it seems yes Apple does not certify an auto-exit of an iOS app, however as said above, we just need to hide (with whatever way) the Authenticator automatically and unveil the 3rd party payment app (which can be any PSD2 compatible app for which we do not have any control to solicit it to bring itself to the foreground). Kindly advise on a solution. Thanks and regards,
Replies
2
Boosts
0
Views
774
Activity
Nov ’21
Creating square views regardless of orientation
I am trying to create a UIView within a UIStackView that I want to always be square regardless of device and orientation. I have seen posting that explain how others have done it (setting constraints between UIView and superview for both height and width - a required set and an optional set - along with a 1:1 aspect constraint for the UIView) , but it no longer seems to work under all instances - in particular iPad and iPhone 11s. Does anyone have any advice on how to make this happen. It seems to me to be a pretty routine thing to do. I've done it before programmatically, but I would really like to get it done within Interface Builder. Any suggestions would be greatly appreciated.
Replies
1
Boosts
0
Views
2.0k
Activity
Nov ’21
UILabel with superscript text
How can make a UILabel look this way in Xcode12?
Replies
2
Boosts
0
Views
2.7k
Activity
Nov ’21
Why does NSStackView prevent resizing of parent view/window?
I'm implementing a horizontal NSStackView with child views of varying size. The stack view should resize horizontally with its parent view, which in turn resizes with the window. I expect the stack view's arranged distribution (fill proportionally) to adjust the distribution of child views as its width changes. I keep hitting the bizarre behavior where the window can't be resized horizontally at all - the vertical/diagonal resize cursors no longer appear, and the window can only be resized vertically. The problem is not that the child view doesn't resize with the window: the child view actually prevents resizing of the window! I first saw this creating an empty NSStackView and adding it to its parent view in code, with layout constraints (top, leading, trailing; also tried width). I tried messing with constraint priorities but that did not correct the issue. (With the stack view not there, its parent view resizes with the window just fine). When I created the NSStackView in the .xib this problem went away, the empty NSStackView resizes horizontally along with its parent, so that's what I'm doing now. However, now when I add a set of arranged subviews in code, it happens again - they are distributed perfectly, but the window again cannot be horizontally resized! The subviews are minimal NSView implementations (drawing their bounds); they do not have intrinsic size. They do each have child NSTextField labels, with autolayout constraints to horizontally resize along with their parents. There are no constraints besides those internal to each child view and its label subview. What am I not understanding about AutoLayout and NSStackView? I cannot imagine an intentional design that would break the user's ability to resize the window in one direction based on anything an NSStackView does, but that's exactly what happens.
Replies
1
Boosts
0
Views
2.4k
Activity
Oct ’21
Resize image with autolayout
My app loads an image at runtime and I want to display it inside a table cell. To do that I created a UIView (trailing/leading/top/bottom: 10) inside the cell and added a UIImageView as its child. What constraints do I need for the child, so the image keeps its proper aspect ration, isn't wider than the width of the screen and there's no unused space (apart from the constraints)? I tried to use: Trailing/leading/top/bottom: 0 Align center x/y This works if the image uses the portrait format but with landscape there's unused space above and below the image. I also tried to set the view's height to ">=50" but no success and I can't just set a max. value because my app has to work on both iPhones and iPads.
Replies
2
Boosts
0
Views
1.5k
Activity
Oct ’21
Ambiguous layout warnings after Xcode 13.0 upgrade
Hi. My 2 years old project shows ambiguous layout warnings after installing Xcode 13.0. The warnings are basically nuisance (layout shows correctly in the app). All the warnings refer to constraints of objects inside a tableview. The warnings start only after cell 16 downwards (distributed across 4 sections, S1: 2 cells, S2: 2 cells, S3: 1 cells, S4: 12 cells, ...). Hence my idea, if there is any limit to the number of cells Xcode 13.0 can handle? Previous Xcode didn't have any (!) issues regarding this portion of the layout. The screenshots just show an example of such a nuisance warning. Any ideas? Thanks.
Replies
2
Boosts
0
Views
1k
Activity
Oct ’21