I have a problem printing an autolayout view in 10.13.2, and I’m wondering if 
there is something wrong with my code or if Apple broke something in 10.13 or a 
more recent update.

I’m using the same view class for printing and screen, but I have a separate 
view object for printing.

I’m overriding printOperation(withSettings)

This is how it works:

1. Create the view
2. Set up and activate constraints
3. Call view.layoutSubtreeIfNeeded()
4. Return NSPrintOperation(view: view, printInfo: printInfo)

After (2) the view frame is empty.
After (3) the view frame is set correctly in 10.12.6, but is empty in 10.13.2

One difference between print and screen views is that the print view doesn’t 
have a superview, but it is constrained by its children, and I am actually 
setting its width and height explicitly:

pageConstraints.append(NSLayoutConstraint(item: view, attribute: .width, 
relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, 
constant: viewWidth))

pageConstraints.append(NSLayoutConstraint(item: view, attribute: .height, 
relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, 
constant: viewHeight))

In 10.12.6, calling view.layoutSubtreeIfNeeded causes the view’s frame to be 
set to {0, 0, viewWidth, viewHeight}
In 10.13.2 this doesn’t happen

I can set the frame manually, but it seems wrong that I should have to do this. 
The consequence of the frame not being set is that nothing is printed!

I don’t have previous versions of 10.13 that I can test on, so I don’t know 
exactly when this got broken (or changed if it isn’t actually broken).

Jeremy

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to