UIActivityController sharing to Microsoft Teams cuts off the modal - ios

Sharing on teams bugs out modal like this
I have implemented UIActivityController where I am sharing an image along with a link but excluding image when sharing it to any app and using the image just for saving it to camera roll. When I try to share to Microsoft Teams, this is what I could see which happens randomly (inconsistent). What could be the cause of this issue? Thank You :)

Try that:
if UIDevice.current.userInterfaceIdiom == .phone {
present(activityView, animated: true) {
}
} else {
// Change Rect to position Popover
popup = UIPopoverController(contentViewController: activityView)
popup.present(from: CGRect(x: view.frame.size.width / 2, y: view.frame.size.width / 2, width: 100, height: 100), in: view, permittedArrowDirections: .any, animated: true)
}

Related

UIActivityViewController animation on iPad

Trying to get an UIActivityViewController to animate like in iOS Photos on iPad:
Code so far:
if UIDevice.current.userInterfaceIdiom == .pad {
activityViewController.preferredContentSize = CGSize(width: 540, height: 720)
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: UIScreen.main.bounds.width / 2 - 280, y: UIScreen.main.bounds.height, width: 540, height: 720)
activityViewController.popoverPresentationController?.permittedArrowDirections = []
}
viewController.present(activityViewController, animated: true, completion: nil)
Checking for iPad and setting size and (final) position. That's how far I got. Tried adding an UIView.animate block to animate the view after it is being presented (changinging the initial position of course). Also tried creating a CATransition with activityViewController.view.layer.add(transition, forKey: nil). No success.

Activity View Controller not showing the entire popup

I am trying to make a drawing app and I want to add the activity view controller. It works on the iPhone, but it will not show the entire view controller on the iPad. I have tried many different approaches based off what I have read, but the result is the same. Any help is appreciate.
Code:
#IBAction func actionsTapped(_ sender: Any) {
// Setting description
let message = "Actions for your drawing"
// Get the image to save
let image = getImage()
let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [message, image], applicationActivities: nil)
// Ipad popup
activityViewController.popoverPresentationController?.sourceView = (self.view)
// Remove Ipad arrow
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
// Pre-configuring activity items
activityViewController.activityItemsConfiguration = [
UIActivity.ActivityType.message,
UIActivity.ActivityType.print,
UIActivity.ActivityType.saveToCameraRoll,
UIActivity.ActivityType.airDrop
] as? UIActivityItemsConfigurationReading
// Exclude
activityViewController.excludedActivityTypes = [
UIActivity.ActivityType.postToWeibo,
UIActivity.ActivityType.addToReadingList,
UIActivity.ActivityType.postToFlickr,
UIActivity.ActivityType.postToVimeo,
UIActivity.ActivityType.postToTencentWeibo,
UIActivity.ActivityType.postToFacebook
]
activityViewController.isModalInPresentation = true
self.present(activityViewController, animated: true, completion: nil)
}
As someone pointed out, which I tried changing the height and width in the sourceRect does not work. See below where I changed
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
to
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 500, height: 500)
My initial thought was that x and y would change the position of the popup and height and width change the size, but it seems that it's the reverse in sourceRect.
It sounds like you're misunderstanding what the sourceRect is. It has nothing to do, in and of itself, with the size of the activity view controller. It determines where the arrow points to.
The activity view controller always has its own full size. I suspect that what's going wrong here is due to this line:
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down
That forces the whole activity view controller to appear above the source rect (i.e. more toward the top of the screen) — but there isn't room. If you just cut that line, the activity view controller may be able to appear where there is room.

How can I print my image instead of save to camera roll? Swift 3, IOS

I have a screenshot button set up so that i can capture the entire view controller (except my status bar an navigation bar) and input that image to the camera roll. The only problem is that if i try to print this image from my camera roll, it prints an image only 1/4 of the page size. The image is too small, and i need it to be 850 by 1100 ("Letter" Size).
How exactly could you code my screenshot to print, instead of a save to camera roll - and to specifically print 850 x 1100 (Letter size).
This is what my screenshot looks like:
///////// screenshot save
#IBAction func buttonAction(_ sender: UIButton) {
//partial screenshot function
let top: CGFloat = 46
let bottom: CGFloat = 0
let size = CGSize(width: view.frame.size.width, height: view.frame.size.height - top - bottom)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
let context = UIGraphicsGetCurrentContext()!
context.translateBy(x: 0, y: -top)
view.layer.render(in: context)
let snapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//Save photo to camera roll
UIImageWriteToSavedPhotosAlbum(snapshot!, nil, nil, nil)
//Flash screen when photo is saved
let shutterView = UIView(frame: view.frame)
shutterView.backgroundColor = UIColor.black
view.addSubview(shutterView)
UIView.animate(withDuration: 0.3, animations: {
shutterView.alpha = 0
}, completion: { (_) in
shutterView.removeFromSuperview()
})
}
Please help! i have no idea what I'm doing. Someone mentioned that i should implement the UIPrintInteractionController, but i have no idea how, as I'm very new to programming.

Xcode, Swift: How to center popover box

Link to my github account with files, simply download zip: https://github.com/jzhang172/modalTest
When I click on the "popover" link, I would like to center the popover in the center of the screen.
I tried referencing some stackoverflow questions such as:
how to center a popoverview in swift
but no luck. I'm a noob in swift and I'm only using swift, not objective C.
Screenshot of what I see:
Replacing
controller?.sourceRect = CGRectMake(0.0, self.view.layer.bounds.height * 0.5,0.0,0.0)
with
controller?.sourceRect = CGRectMake(self.view.layer.bounds.width * 0.5, self.view.layer.bounds.height * 0.5,0.0,0.0)
will center the popover content horizontally and vertically.
You can center the UIPopover in your view with the code below.
let controller = vc.popoverPresentationController
controller?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
controller?.sourceView = self.view
controller?.sourceRect = CGRectMake(0.0, self.view.layer.bounds.height * 0.5,0.0,0.0)
vc.preferredContentSize=CGSize(width: 400, height: 200)
Swift 3:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let popoverPresentationController = segue.destination.popoverPresentationController {
let controller = popoverPresentationController
controller.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
controller.sourceView = self.view
controller.sourceRect = CGRect(x: UIScreen.main.bounds.width * 0.5 - 200, y: UIScreen.main.bounds.height * 0.5 - 100, width: 400, height: 200)
segue.destination.preferredContentSize=CGSize(width: 400, height: 200)
}
}

UIDocumentInteractionController PopOver on iPad

When you display a UIActionSheet on the iPad, it appears as a centered UIPopover with no arrow.
I have a UIDocumentInteractionController, and when I call presentOpenInMenuFromRect:inView:animated:, I am looking for the same behavior with the popover that appears there. Anyway to do that? I know you can have no arrow on a popover by setting the PermittedArrowDirections to 0, but that doesn't seem to be an option here.
You can use UIActivityController instead
let url = #Your File URL#
var activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
activityViewController.popoverPresentationController?.sourceView = view
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: view.frame.midX, y: view.frame.midY,
width: 0, height: 0)

Resources