Hi Ty for playing
Auto Layout
RSS for tagCreate a user interface that dynamically responds to changes in the available screen space using Auto Layout.
Posts under Auto Layout tag
14 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi all,
Firebase statistics show that some crashes seem to occur suddenly. Can you give me some suggestions?
Users also meet the following requirements:
iOS18 and above
RTL language
From the stack frame, the crash occurred in the transition animation project, but I did not reproduce this stack frame
A very small number of users can experience it twice
The crashed page is relatively complex, and it is a mixture of auto-layout and frame
I retrieved some other articles, but they don’t seem to be the same problem
https://developer.apple.com/forums/thread/693118
https://stackoverflow.com/questions/56027014/collectionview-crashing-in-nsisengine-after-a-few-scrolls
Thank you for reading, looking forward to your reply ;)
CoreAutoLayout: _engineVar_rawRemove
After upgrading to Xcode16RC, in an old project based on ObjC, I directly used the following controller code in AppDelegate:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *b = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 44, 44)];
[b setTitle:@"title" forState:UIControlStateNormal];
[self.view addSubview:b];
[b addTarget:self action:@selector(onB:) forControlEvents:UIControlEventTouchUpInside];
}
- (IBAction)onB:(id)sender{
PHPickerConfiguration *config = [[PHPickerConfiguration alloc]initWithPhotoLibrary:PHPhotoLibrary.sharedPhotoLibrary];
config.preferredAssetRepresentationMode = PHPickerConfigurationAssetRepresentationModeCurrent;
config.selectionLimit = 1;
config.filter = nil;
PHPickerViewController *picker = [[PHPickerViewController alloc]initWithConfiguration:config];
picker.modalPresentationStyle = UIModalPresentationFullScreen;
picker.delegate = self;
[self presentViewController:picker animated:true completion:nil];
}
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results{
}
Environment: Simulator iPhone 15 Pro (iOS18)
Before this version (iOS17.4), clicking the button to pop up the system photo picker interface was normal (the top boundary was within the SafeAreaGuide area), but now the top boundary of the interface aligns directly to the top of the window, and clicking the photo cell is unresponsive.
If I create a new Target, using the same codes, the photo picker page does not have the above problem.
Therefore, I suspect it may be due to the old project’s .proj file’s info.plist, buildSetting, or buildPhase lacking some default configuration key value required by the new version, (My project was built years ago may be from iOS13 or earlier ) but I cannot confirm the final cause.
iOS18.0 has the additional messages:
objc[79039]: Class UIAccessibilityLoaderWebShared is implemented in both /Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/AccessibilityBundles/WebCore.axbundle/WebCore (0x198028328) and /Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/AccessibilityBundles/WebKit.axbundle/WebKit (0x1980fc398). One of the two will be used. Which one is undefined.
AX Safe category class 'SLHighlightDisambiguationPillViewAccessibility' was not found!
Has anyone encountered the same issue as me?
Repo is here
Visual Description is here:
Basically the red view should never be inside the blue view. The red view has a fixed aspect ratio. The blue view initially has an aspect ratio different from the red view and is animated to have the same aspect ratio.
The red view is constrained inside the blue view as follows:
let ac = brokenView.widthAnchor.constraint(equalTo: brokenView.heightAnchor, multiplier: 9/16)
let xc = brokenView.centerXAnchor.constraint(equalTo: animView.centerXAnchor)
let yc = brokenView.centerYAnchor.constraint(equalTo: animView.centerYAnchor)
let widthC = brokenView.widthAnchor.constraint(equalTo: animView.widthAnchor)
widthC.priority = .defaultLow
let gewc = brokenView.widthAnchor.constraint(greaterThanOrEqualTo: animView.widthAnchor)
let geHC = brokenView.heightAnchor.constraint(greaterThanOrEqualTo: animView.heightAnchor)
geHC.priority = .required
So the red view should start at equal width, but prioritize always been taller and wider than the blue view while staying centered and keeping a fixed aspect ratio. As you can see in the visual description it is not priortizing being taller.
Any suggestions on how to fix, work around, or otherwise get past this would be appreciated. Really trying to avoid manually doing a spring animation with keyframes and an assload of math.
I have filed a bug on feedback assistant, but figured someone here might have experience//know how. Thanks
I have a ZStack that contains a VStack with 2 views (view1 and view2) and a third view (view3). So, is either that view1 and View1 are visible, or view3 is visible. This is the relevant code:
ZStack {
VStack {
view1()
View2()
}
if showView3
View3()
}
view1 and view2 are 400px in width and 200px in height, while view3 is 400 x 400 px, so that it completely overwrite view1/view2 when visible.
The problem I'm trying to solve is that the border of a TextField placed in view1 is visible when showView3 is true, what should not be happening (possible glitch in swift?).
To show the problem, I prepared a code sample, which shows that when view3 is active, it completely overwrites view1/view2, but still, the border of the TextField remains visible. (See screenshot below)
struct TestZStackView: View {
@State private var showView3 = false
var body: some View {
ZStack {
VStack {
Toggle("view3", isOn: $showView3)
View1()
.frame(width: 400, height: 200)
.background(Color.red)
.zIndex(1)
View2()
.frame(width: 400, height: 200)
.background(Color.green)
.zIndex(1)
}
if showView3 {
View3()
.frame(width: 400, height: 400)
.background(Color.blue)
.zIndex(2)
}
}
}
}
struct View1: View {
var body: some View {
TextField("Enter text", text: .constant(""))
.padding()
.cornerRadius(5)
.textFieldStyle(RoundedBorderTextFieldStyle())
.zIndex(1)
}
}
struct View2: View {
var body: some View {
Color.clear
}
}
struct View3: View {
var body: some View {
Color.black // (Ensure no transparency)
}
}
zIndex() are not required, I just placed them to see if the problem get solved, but it may no difference.
BTW, in the code above, the visible border disappears if the view is minimized, but that is not the case in the real app I'm working on.
In the screenshots attached, it can be seen how the TextField border remains visible when view3 is active
("https://developer.apple.com/forums/content/attachment/d0e75f25-d36e-4361-af64-54252d1f2a98" "title=Screenshot 2024-05-24 at 10.06.03 PM.png;width=800;height=632")
I have a ZStack that contains a VStack with 2 views (view1 and view2) and a third view (view3). So, is either that view1 and View1 are visible, or view3 is visible. This is the relevant code:
ZStack {
VStack {
view1()
View2()
}
if showView3
View3()
}
view1 and view2 are 400px in width and 200px in height, while view3 is 400 x 400 px, so that it completely overwrite view1/view2 when visible.
The problem I'm trying to solve is that the border of a TextField placed in view1 is visible when showView3 is true, what should not be happening (possible glitch in swift?).
To show the problem, I prepared a code sample, which shows that when view3 is active, it completely overwrites view1/view2, but still, the border of the TextField remains visible. (See screenshot below)
struct TestZStackView: View {
@State private var showView3 = false
var body: some View {
ZStack {
VStack {
Toggle("view3", isOn: $showView3)
View1()
.frame(width: 400, height: 200)
.background(Color.red)
.zIndex(1)
View2()
.frame(width: 400, height: 200)
.background(Color.green)
.zIndex(1)
}
if showView3 {
View3()
.frame(width: 400, height: 400)
.background(Color.blue)
.zIndex(2)
}
}
}
}
struct View1: View {
var body: some View {
TextField("Enter text", text: .constant(""))
.padding()
.cornerRadius(5)
.textFieldStyle(RoundedBorderTextFieldStyle())
.zIndex(1)
}
}
struct View2: View {
var body: some View {
Color.clear
}
}
struct View3: View {
var body: some View {
Color.black // (Ensure no transparency)
}
}
zIndex() are not required, I just placed them to see if the problem get solved, but it may no difference.
BTW, in the code above, the visible border disappears if the view is minimized, but that is not the case in the real app I'm working on.
In the screenshots attached, it can be seen how the TextField border remains visible when view3 is active
("https://developer.apple.com/forums/content/attachment/d0e75f25-d36e-4361-af64-54252d1f2a98" "title=Screenshot 2024-05-24 at 10.06.03 PM.png;width=800;height=632")
Hi everyone i am having trouble with layout. I am using storyboard for UI. While most of the iphone version are ok with my auto layout ... the first generation Iphone SE is giving me errors. To publish app on app store do i need it to be working perfectly on first generation Iphone SE too ? Any link or knowledge on layout for story board is much appreciated.
Microsoft did a very good job with UWP, when you build app for Windows Phone, those app automatically scales to big screen (horizontal oriented devices) Tablet, PC, Xbox. Kind of similar to website that have responsive UI.
Eitherway, Apple needs to do something similar... there is no reason why phone apps are so small on my iMac.
Even if it is already supported, Apple needs to encourage developers to implement it.
This crash happens online and cannot be tested and reproduced. I need help. Thank you very much.
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000018b4190d0
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [338]
Triggered by Thread: 7
Last Exception Backtrace:
0 CoreFoundation 0x180cd7c60 __exceptionPreprocess + 216 (NSException.m:200)
1 libobjc.A.dylib 0x198507ee4 objc_exception_throw + 56 (objc-exception.mm:565)
2 CoreAutoLayout 0x1987cb000 _AssertAutoLayoutOnAllowedThreadsOnly + 412 (NSISEngine.m:0)
3 CoreAutoLayout 0x1987cdb7c -[NSISEngine withBehaviors:performModifications:] + 32 (NSISEngine.m:1975)
4 UIKitCore 0x1831262fc -[UIView _resetLayoutEngineHostConstraints] + 80 (NSLayoutConstraint_UIKitAdditions.m:1426)
5 UIKitCore 0x1830fc0c0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2376 (UIView.m:18416)
6 QuartzCore 0x18477c520 CA::Layer::layout_if_needed(CA::Transaction*) + 528 (CALayer.mm:10118)
7 QuartzCore 0x18476f294 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 132 (CALayer.mm:2480)
8 QuartzCore 0x184782cc8 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 (CAContextInternal.mm:2612)
9 QuartzCore 0x18478b79c CA::Transaction::commit() + 708 (CATransactionInternal.mm:449)
10 QuartzCore 0x1847dfe04 CA::Transaction::release_thread(void*) + 224 (CATransactionInternal.mm:651)
11 libsystem_pthread.dylib 0x1dc052d90 _pthread_tsd_cleanup + 520 (pthread_tsd.c:388)
12 libsystem_pthread.dylib 0x1dc055c08 _pthread_exit + 80 (pthread.c:1717)
13 libsystem_pthread.dylib 0x1dc05124c _pthread_wqthread_exit + 100 (pthread.c:2559)
14 libsystem_pthread.dylib 0x1dc050e88 _pthread_wqthread + 420 (pthread.c:2593)
15 libsystem_pthread.dylib 0x1dc05092c start_wqthread + 8 (:-1)
Hi
can you add new feature in Pages and Numbers using Ai to apply style from PDF or template to documents, so ai arrange footers and headers and fonts , pages breaks , pages numbers, like one in PDF or templates , so we can auto format documents to desired look standard, also for Numbers. So we can on raw text upload pdf of another documents or report and get documents in that style for export to pdf or print
Best regards,
giving this every time
*** Assertion failure in void _engineVar_rawRemove(NSISEngineVar)(), NSISEngine_EngineVar.h:181
2024-03-21 16:29:48.644662+0530 Yanabea[6857:1455909] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Not possible to remove variable: 922: <unknown var (bug!) with engine as delegate:0x282bd7d80>{id: 10158} colIndex:103 from engine <NSISEngine: 0x1500b4350>{ delegate:0x14bdc8ca0
EngineVars:
.
.
.
.
78 -> 2
79 -> 1
80 -> 1
}.'
terminating with uncaught exception of type NSException
and rest thousands of line of logs that I am tried to attached in the attachment but it is not supporting.
I am new to using iOS Objective-C size classes like Regular, compact, Any. I found that Compact size classes are anything less than ~640 pts and
Regular size classes are anything larger than ~640 pts . Is that correct for both iphone and ipad?
How can I use size class to make an image full screen on all the iphone and ipad devices and on any orientation? How many images will I need? Any help and insight is greatly appreciated!
I am trying to self size DTAttributedTextContentView inside the collection cell based on its attributed text. The problem I face is that when I set attributedTextContentView width constraints like so:
attributedTextContentView.widthAnchor.constraint(lessThanOrEqualToConstant: 260)
it applies the whole constant width (in this case 260) to the textContentView, even if attributedString length is smaller than the width, leaving some extra space:
My question is, how to size the frame of DTAttributedTextContentView so that it just encloses the text that it contains?
Initially I used basic UITextView, but the scrolling of cells through collection view is not that smooth when there are multiple cells, and also it gives possibility to easy access the last line of the text inside, which I need for my app, so I would like to stick to DTAttributedTextContentView.
Here is the sample code for testing:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureCollectionView()
}
// MARK: - Collection view setup
let collectionView: UICollectionView = {
let layout = UICollectionViewCompositionalLayout { (section, environment) -> NSCollectionLayoutSection? in
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(10))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let group = NSCollectionLayoutGroup.vertical(layoutSize: itemSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 5
return section
}
layout.configuration.scrollDirection = .vertical
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.register(ConversationCollectionViewCell.self, forCellWithReuseIdentifier: "ConversationCell")
return collectionView
}()
private func configureCollectionView() {
collectionView.dataSource = self
collectionView.backgroundColor = .brown
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
}
// MARK: - Collection Data Source
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ConversationCell", for: indexPath) as! ConversationCollectionViewCell
return cell
}
}
// MARK: - Collection View Custon Cell
final class ConversationCollectionViewCell: UICollectionViewCell, DTAttributedTextContentViewDelegate {
var mainCellContainerView = UIView()
var attributedTextContentView = DTAttributedTextContentView()
//MARK: - LIFECYCLE
override init(frame: CGRect) {
super.init(frame: frame)
setupmainCellContainerView()
setupAttributedTextContentView()
layoutIfNeeded()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - UI STEUP
private func setupmainCellContainerView() {
contentView.addSubview(mainCellContainerView)
mainCellContainerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
mainCellContainerView.topAnchor.constraint(equalTo: contentView.topAnchor),
mainCellContainerView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
mainCellContainerView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
mainCellContainerView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
])
}
private func setupAttributedTextContentView() {
mainCellContainerView.addSubview(attributedTextContentView)
attributedTextContentView.backgroundColor = .systemIndigo
attributedTextContentView.delegate = self
attributedTextContentView.sizeToFit()
let attributedString = NSAttributedString(string: "Simple message for testing purpose @", attributes: [
.font: UIFont(name: "HelveticaNeue", size: 17),
.foregroundColor: UIColor.white,
.paragraphStyle: {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
paragraphStyle.lineBreakMode = .byWordWrapping
return paragraphStyle
}()
])
attributedTextContentView.attributedString = attributedString
attributedTextContentView.contentMode = .redraw
attributedTextContentView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
attributedTextContentView.widthAnchor.constraint(lessThanOrEqualToConstant: 260),
attributedTextContentView.topAnchor.constraint(equalTo: mainCellContainerView.topAnchor),
attributedTextContentView.bottomAnchor.constraint(equalTo: mainCellContainerView.bottomAnchor),
])
}
}
I am developing an iOS app using SwiftUI and have encountered an Auto Layout constraint conflict issue that appears when tapping on a TextField within a LoginView. I've tried several troubleshooting steps but haven't been able to resolve it.
Error Message:
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x6000021298b0 'accessoryView.bottom' _UIRemoteKeyboardPlaceholderView:0x10460dd10.bottom == _UIKBCompatInputView:0x1059220e0.top (active)>",
"<NSLayoutConstraint:0x60000217a620 'assistantHeight' SystemInputAssistantView.height == 45 (active, names: SystemInputAssistantView:0x10591ce60 )>",
"<NSLayoutConstraint:0x60000217d090 'assistantView.bottom' SystemInputAssistantView.bottom == _UIKBCompatInputView:0x1059220e0.top (active, names: SystemInputAssistantView:0x10591ce60 )>",
"<NSLayoutConstraint:0x60000217d040 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x10460dd10]-(0)-[SystemInputAssistantView] (active, names: SystemInputAssistantView:0x10591ce60 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000217d040 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x10460dd10]-(0)-[SystemInputAssistantView] (active, names: SystemInputAssistantView:0x10591ce60 )>
This error appears in the console when I click on the TextField in my LoginView while running the code on a simulation. The app doesn't crash, but the console indicates there is a constraint conflict related to the keyboard. Here's my LoginView:
struct LoginView: View {
@StateObject var viewModel = LoginViewModel()
var body: some View {
NavigationStack {
VStack {
Spacer()
Image("logo")
.resizable()
.scaledToFit()
.frame(width: 150, height: 100)
VStack {
TextField("Enter your email", text: $viewModel.email)
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
.modifier(TextFieldModifier())
SecureField("Enter your password", text: $viewModel.password)
.modifier(TextFieldModifier())
}
Button {
print("Show forgot password")
} label: {
Text("Forgot Password")
.font(.footnote)
.fontWeight(.semibold)
.padding(.top)
.padding(.trailing, 20)
}
.frame(maxWidth: .infinity, alignment: .trailing)
Button {
Task { try await viewModel.signIn() }
} label: {
Text("Login")
.font(.subheadline)
.fontWeight(.semibold)
.foregroundColor(.white)
.frame(width: 360, height: 44)
.background(Color(.black))
.cornerRadius(8)
}
.padding(.vertical)
HStack {
Rectangle()
.frame(width: (UIScreen.main.bounds.width / 2) - 40, height: 0.5)
Text("OR")
.font(.footnote)
.fontWeight(.semibold)
.foregroundColor(.gray)
Rectangle()
.frame(width: (UIScreen.main.bounds.width / 2) - 40, height: 0.5)
}
.foregroundColor(.gray)
HStack {
Image("facebook_logo")
.resizable()
.frame(width: 20, height: 20)
Text("Continue with Facebook")
.font(.footnote)
.fontWeight(.semibold)
.foregroundColor(Color(.systemBlue))
}
.padding(.top, 8)
Spacer()
Divider()
NavigationLink {
AddEmailView()
.navigationBarBackButtonHidden(true)
} label: {
HStack (spacing: 3) {
Text("Don't have an account?")
Text("Sign Up")
.fontWeight(.semibold)
}
.font(.footnote)
}
.padding(.vertical, 16)
}
}
}
}
#Preview {
LoginView()
}
And my TextFieldModifier:
struct TextFieldModifier: ViewModifier {
func body(content: Content) ->some View {
content
.font(.subheadline)
.padding(12)
.background(Color(.systemGray6))
.cornerRadius(10)
.padding(.horizontal, 24)
.padding(.top)
}
}
Attempts to Resolve:
I've checked the TextFieldModifier for any potential issues but it seems standard.
I've tried simplifying the view by removing other elements, but the issue persists.
The issue seems to occur regardless of the simulator device or iOS version I use.
Questions:
What could be causing this Auto Layout constraint conflict in a SwiftUI app?
Are there any known issues with SwiftUI's TextField and keyboard interactions that might lead to such constraints issues?
Any suggestions on how to debug or resolve this constraint conflict?