Post

Replies

Boosts

Views

Created

repeatCount in UIViewPropertyAnimator
I have a func to flash a view a number of times and execute closure at the end. The following code with UIView.setAnimationRepeatCount works OK: animation occurs the requested number of times and afterEnd closure executes at the end. func flashIt(repeated: Int, cycleTime: Double, delayed: Double = 5.0, afterEnd: (() -> Void)? = nil) { if repeated < 0 { return } let initAlpha = self.alpha UIView.animate(withDuration: cycleTime, delay: delayed, options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat], animations: { UIView.setAnimationRepeatCount(Float(repeated)) self.alpha = 0.1 // Not 0.0, to allow user interaction }, completion: { (done: Bool) in self.alpha = initAlpha afterEnd?() } ) } To address UIView.setAnimationRepeatCount deprecation, I now try this (inspired by https://stackoverflow.com/questions/47496584/uiviewpropertyanimator-reverse-animation) func flashIt(repeated: Int, cycleTime: Double, delayed: Double = 5.0, afterEnd: (() -> Void)? = nil) { if repeated < 0 { return } let initAlpha = self.alpha let animator = UIViewPropertyAnimator(duration: cycleTime, curve: .linear) { self.alpha = 0.1 } animator.addCompletion { _ in let reverseAnimator = UIViewPropertyAnimator(duration: cycleTime, curve: .linear) { self.alpha = initAlpha } reverseAnimator.addCompletion { [self] _ in flashIt(repeated: repeated-1, cycleTime: cycleTime, delayed: 0) // without delay here } reverseAnimator.startAnimation() if repeated <= 1 { // 1 and not 0, otherwise an extra loop… afterEnd?() // Not called return } } animator.startAnimation(afterDelay: delayed) } The flash works, but afterEnd closure is never called. I've tried to call if repeated <= 1 { // 1 and not 0, otherwise an extra loop… afterEnd?() // Not called return } in other places, to no avail. What do I miss ? Is there a better and simpler way to have a RepeatCount with UIViewPropertyAnimator ?
3
0
1.5k
Dec ’21
UIApplication.openSettingsURLString does not work on iPadOS 15 simulator ?
The following code opens the app settings, including preferred language. func openSettings() { guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { return } if UIApplication.shared.canOpenURL(settingsUrl) { UIApplication.shared.open(settingsUrl, completionHandler: nil) } } That works well in iOS (14.6 or 15.2), on iPadOS 14.4 ( both device and simulator) But on iPadOS 15.2 simulator, the preferred language setting for the app does not show. I noticed this in 2 different apps.
1
0
1k
Dec ’21
SegmentedControl do not work correctly on iPhone 13Mini simulator
UISegmented controls seem not to work correctly in iPhone 13 Mini simulator. When tapping on a segment, control does not react before 30 to 40 s ; then it shows uncomplete redraw: I also noted similar lag in updating display when some label text changes. Configuration: MacOS 11.6.1 Xcode 13RC iOS 15.0 simulator. It works ok on a few other simulators I tested. I created an extremely simple project to reproduce: new project in Xcode 13RC added a segmentedControl at bottom of view, constrained to leading and trailing 0 to the safe area set selected color to red. run on iPhone 13 mini simulator I will test later with Xcode 13.2ß
1
0
904
Nov ’21
Change in Watch 7 in rounded corners of WKInterfaceLabel or WKInterfaceGroup
When testing in simulator with Xcode 13, I noted a subtle difference in the display of WKInterfaceLabel between Watch series 6 and series 7. WKInterfaceLabel is in a WKInterfaceGroup. On Series 7: the text Fast Driving is clipped with round corner at top and bottom On Series 6, round clipping is much less (noticeable on leading F and D) I could not find what parameter has changed in IB nor how to change this round corner value. Nor why such a change ?
3
0
2.0k
Oct ’21
Excluding activity types for UIActivityViewController: some are still present
I try to exclude some activities from UIActivity. It works as expected when exclusion is done directly with the activity, as with: UIActivity.ActivityType.message, UIActivity.ActivityType.airDrop but not when activity is declared with an init as with: UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"), UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share"), So, with the following code: let excludedActivityTypes = [ UIActivity.ActivityType.message, UIActivity.ActivityType.airDrop, UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"), UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share") ]         let activityVC = UIActivityViewController(activityItems: [modifiedPdfURL], applicationActivities: nil)          activityVC.excludedActivityTypes = excludedActivityTypes message and airDrop do not show, but WhatsApp and IFTTT still show. I have tested with         activityVC.completionWithItemsHandler = { (activity, success, modifiedItems, error) in             print("activity: \(activity), success: \(success), items: \(modifiedItems), error: \(error)")         } that WhatsApp and IFTTT services are effectively the ones listed here. When selecting WhatsApp, print above gives: activity: Optional(__C.UIActivityType(_rawValue: net.whatsapp.WhatsApp.ShareExtension)), success: false, items: nil, error: nil
4
0
5.2k
Aug ’21
Perform action once UIActivityViewController has completed item action
I use UIActivityViewController to airDrop pdfFile (pdfURL) from iPhone to iMac. Works well, file is airDropped. let activityVC = UIActivityViewController(activityItems: [pdfURL], applicationActivities: nil) present(activityVC, animated: true, completion: nil) I want to customise it: limit services to AIrDrop and mail How can I exclude such services as WhatsApp, Notes… ? perform some action once the file has completed airDrop or once cancelled. I tried to implement with completionWithItemsHandler:         activityVC.completionWithItemsHandler = { (activity, success, items, error) in             print("Completed")         } This doesn't work, print is not executed. My ultimate goal is to close the activityVC automatically once action was completed, without need to tap close button. Should I define some content for applicationActivities ?
2
0
918
Aug ’21
Rotating a page in a pdf file - and get a mirrored image
I try to rotate a page 180° in a pdf file. I nearly get it, but the page is also mirrored horizontally. Some images to illustrate: Initial page: Result after rotation (see code): it is rotated 180° BUT mirrored horizontally as well: The expected result It is just as if it was rotated 180°, around the x axis of the page. And I would need to rotate 180° around z axis (perpendicular to the page). It is probably the result of writeContext!.scaleBy(x: 1, y: -1) I have tried a lot of changes for transform, translate, scale parameters, including removing calls to some of them, to no avail. @IBAction func createNewPDF(_ sender: UIButton) { var originalPdfDocument: CGPDFDocument! let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) let documentsDirectory = urls[0] // read some pdf from bundle for test if let path = Bundle.main.path(forResource: "Test", ofType: "pdf"), let pdf = CGPDFDocument(URL(fileURLWithPath: path) as CFURL) { originalPdfDocument = pdf } else { return } // create new pdf let modifiedPdfURL = documentsDirectory.appendingPathComponent("Modified.pdf") guard let page = originalPdfDocument.page(at: 1) else { return } // Starts at page 1 var mediaBox: CGRect = page.getBoxRect(CGPDFBox.mediaBox) // mediabox which will set the height and width of page let writeContext = CGContext(modifiedPdfURL as CFURL, mediaBox: &mediaBox, nil) // get the context var pageRect: CGRect = page.getBoxRect(CGPDFBox.mediaBox) // get the page rect writeContext!.beginPage(mediaBox: &pageRect) let m = page.getDrawingTransform(.mediaBox, rect: mediaBox, rotate: 0, preserveAspectRatio: true) // Because of rotate 0, no effect ; changed rotate to 180, then get an empty page writeContext!.translateBy(x: 0, y: pageRect.size.height) writeContext!.scaleBy(x: 1, y: -1) writeContext!.concatenate(m) writeContext!.clip(to: pageRect) writeContext!.drawPDFPage(page) // draw content in page writeContext!.endPage() // end the current page writeContext!.closePDF() } Note: This is a follow up of a previous thread, https://developer.apple.com/forums/thread/688436
2
0
2.1k
Aug ’21
Search in Download / more broken ?
In the new version of download > More, there doesn't seem to be a way to filter search efficiently. I searched for instance for MacOS (to see all releases). I get a very long list (200+) references, with a lot of Xcode, but nothing specific to MacOS. If I search for Xcode 11, I get all Xcode references: I added quotes to try and force an exact search, I just get a Java extension… That was not the case in the previous version of the more page. Or do I miss something ?
2
0
621
Jul ’21
Getting back from Splitview
In this app, I have: a VC as entry point (root) which segues (push) to a SplitViewController On iPad, when I get into the splitView, I can get back to the root by dragging down the split view. But on iPhone, this does not work: even though presentation is .automatic, Splitview covers all screen. No way to get back. I tried to create a back button in the detail views… Could not get it. What is the best way to do this ? is there a setup for the initial segue or the views presentation modes to allow pop back ? can I add a back button ? Where, calling what action to return ? I cannot embed splitViewController in nav stack … I would like to have the same solution on both iPhone and iPad…
1
0
625
Jun ’21
Lines numbering in Code Block
The Code Block doesn't number lines anymore. The work around is to ask for Numbered list in addition to Code block. Just applying Code Block: required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonInit() } Code Block AND Numbered List (or the other order) 1. required init?(coder aDecoder: NSCoder) { 2. super.init(coder: aDecoder) 3. commonInit() 4. } Is there another way to get numbering directly ?
4
0
910
Jun ’21
Sandbox - security scoped URL - MacOS
In a MacOS App: When I create a file (in a folder), I save a security bookmark for the file. if I ask user to authorise its folder (before creating the file in it), I can save its bookmark too, allowing to create other files in this folder. So, when I create a file and need to create a companion (eg, a Results file), I first ask access to the folder, then create the file and create the results file in the same folder (hence having sandbox authorisation). My understanding is that it is not possible to programmatically create and save the folder bookmark, after deriving its url from the file url, without requesting user to explicitly grant access (with NSOpen panel) ? Which would be very logical as it would deny the goal of security bookmarks. So, is user explicit authorisation required (logical but creates more complexity when user moves files in the Finder). Note: In fact don't really need it, as I save bookmark for every accessed file, but I would like to know.
1
0
802
Apr ’21
Distribution of MacApp outside of Appstore for a demo version
I consider the following distribution scheme for some Mac App: distribute the commercial (paying) version on Appstore propose a free demo version (of course limited in some aspects) on a web site. This would of course be notarised. The reason is to avoid having several versions on the Appstore which could create some confusion. The 2 versions would have similar names and differ essentially in the size of data they can handle. Does anyone know if this is authorised by the Appstore Guidelines ? Or must I publish both on the AppStore ? Is there a risk my app being rejected as spam ?
1
0
592
Apr ’21