Posts

Post not yet marked as solved
0 Replies
1.5k Views
For years a code for sharing something on iOS was something like this:@IBAction func shareAll(_ sender: UIButton) { let text ="text..." let image = UIImage(named: "Product") let myWebsite = NSURL(string:"https://somelink.com") let shareAll= [text , image! , myWebsite] let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil) activityViewController.popoverPresentationController?.sourceView = self.view self.present(activityViewController, animated: true, completion: nil) }Well, it does not work on iPads with iOS13+ anymore unless we addactivityViewController.popoverPresentationController?.sourceRect = ...I doubt that behaviour was intended. Old code still works on iPhones. Console trace is below:[LayoutConstraints] Unable to simultaneously satisfy constraints. 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:0x600001c68eb0 LPLinkView:0x7f834f833900.leading == UILayoutGuide:0x600000609a40'UIViewLayoutMarginsGuide'.leading (active)>", "<NSLayoutConstraint:0x600001c689b0 H:[LPLinkView:0x7f834f833900]-(59)-| (active, names: '|':_UIActivityContentTitleView:0x7f834f831f50 )>", "<NSLayoutConstraint:0x600001c304b0 H:|-(0)-[_UIActivityContentTitleView:0x7f834f831f50] (active, names: '|':_UINavigationBarContentView:0x7f834cd91c80 )>", "<NSLayoutConstraint:0x600001c24910 _UIActivityContentTitleView:0x7f834f831f50.trailing == _UINavigationBarContentView:0x7f834cd91c80.trailing (active)>", "<NSLayoutConstraint:0x600001c600a0 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7f834cd91c80.width == 0 (active)>", "<NSLayoutConstraint:0x600001c684b0 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x600000609a40'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIActivityContentTitleView:0x7f834f831f50 )>")Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600001c68eb0 LPLinkView:0x7f834f833900.leading == UILayoutGuide:0x600000609a40'UIViewLayoutMarginsGuide'.leading (active)>
Posted
by KarymovDN.
Last updated
.
Post not yet marked as solved
6 Replies
680 Views
I've found that UIView becomes twice slower in terms of performing UIImage.drawAt after suspend/resume. Its ability in terms of String.drawAt or filling rectangles stays the same, which makes it less likely to be a mistake of mine. Recreating view fixes the problem, but one can't expect all developers recreating their views hierarchy after resume. I see the problem on all devices and simulators on iOS 9-13 (did not check older ones).Code sample below requires an image asset called card (mine was 112x145 PNG with transparency, but I don't think it matters). Just add it to x1, x2, x3 to make sure that a native density is present (otherwise upscaling becomes the slowest operation instead of drawing). If your test runs at maximum 60 FPS, increase max constant in the last method of example.After pressing Home or Power or other ways of suspending, observed FPS is twice lower.import UIKit @UIApplicationMain class AppDelegate: UIResponder,UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)->Bool { self.window=UIWindow(frame: UIScreen.main.bounds) window!.makeKeyAndVisible() let testViewController=TestViewController() window!.rootViewController=testViewController Runner._instance.testViewController=testViewController return true } func applicationDidEnterBackground(_ application: UIApplication) { Runner._instance.stop() } func applicationDidBecomeActive(_ application: UIApplication) { Runner._instance.start() } func applicationWillTerminate(_ application: UIApplication) { Runner._instance.stop() } } class Runner: NSObject { static let _instance=Runner() var testViewController: TestViewController! var displayLink: CADisplayLink! var fps=0 var lastFpsCounterTime=Date().timeIntervalSince1970 var fpsCounter=0 func start() { if displayLink == nil { displayLink=CADisplayLink(target: self,selector: #selector(Runner.run)) displayLink.add(to: RunLoop.main,forMode: RunLoop.Mode.common) } } func stop() { displayLink?.invalidate() displayLink=nil } @objc func run() { if lastFpsCounterTime+1<Date().timeIntervalSince1970 { fps=fpsCounter lastFpsCounterTime=Date().timeIntervalSince1970 fpsCounter=0 } fpsCounter+=1 testViewController.view.setNeedsDisplay() } } class TestViewController: UIViewController { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) loadView() } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil,bundle: nibBundleOrNil) loadView() } override func loadView() { view=TestView(frame: UIScreen.main.bounds) } } class TestView: UIView { let image=UIImage(named: "card")! required init?(coder: NSCoder) { super.init(coder: coder) } override init(frame: CGRect) { super.init(frame: frame) isOpaque=true } override func draw(_ _rect: CGRect) { let context=UIGraphicsGetCurrentContext()! context.setFillColor(red: 1, green: 1, blue: 1, alpha: 1) context.fill(bounds) let max=50 //Choose max high enough to get less than 60 FPS let time=Date().timeIntervalSince1970 for i in 1...max { image.draw(at: CGPoint(x: (image.size.width+bounds.width)*CGFloat(time.truncatingRemainder(dividingBy: Double(1+i))/Double(1+i))-image.size.width,y: bounds.height*CGFloat(i)/CGFloat(max))) } let font=UIFont(name: "Arial", size: 15)! let textFontAttributes=[NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: UIColor(red: 1, green: 0, blue: 0, alpha: 1), NSAttributedString.Key.paragraphStyle: NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle] "FPS: \(Runner._instance.fps)".draw(at: CGPoint(x: 2,y: 30),withAttributes: textFontAttributes) } }
Posted
by KarymovDN.
Last updated
.