如何获取UIScrollView可见区域的1:1屏幕截图?内容可能比UIScrollView边界更大或更小,也可能是半隐藏(我已经为较小的内容实现了自定义滚动,所以它不在左上角).我在模拟器上取得了预期的结果,但在设备本身上却没有:
-(UIImage *)imageFromCombinedContext:(UIView *)background {
UIImage *image;
CGRect vis = background.bounds;
CGSize size = vis.size;
UIGraphicsBeginImageContext(size);
[background.layer affineTransform];
[background.layer renderInontext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imref = CGImageCreateWithImageInRect([image CGImage], vis);
image = [UIImage imageWithCGImage:imref];
CGImageRelease(imref);
return image;
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,我有一个自定义UISlider.
但是,我遇到了一些关于如何使默认拇指看起来像iOS控制中心那样小的问题.
请注意,我想要相同的iOS拇指,而不是自定义拇指图像.到目前为止,我已经尝试thumbRect(forBounds...)但没有运气.
有什么建议?
添加了一个UIImageVIew(imageView)self.view,捕获视图到相册完美地工作:
CGSize size = CGSizeMake(self.view.frame.size.height, self.view.frame.size.width);
UIGraphicsBeginImageContext(size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
Run Code Online (Sandbox Code Playgroud)
但是,如果imageView子视图通过以下方式旋转:
[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
Run Code Online (Sandbox Code Playgroud)
self.view再次捕获并不反映旋转.子视图imageView好像没有旋转.
如何使renderInContext子视图旋转CABasicAnimation?
更新:
警告:CALayer/-renderInContext:方法未实现完整的Core Animation组合模型.下面提供的代码将能够解决大多数情况,但有些事情CALayer/-renderInContext:方法无法正确呈现,因此您可能希望联系开发人员技术支持部门以获取变通方法请求.
官方Apple技术问答QA1703建议联系开发人员技术支持以获取变通请求.
是否已存在解决方法?
我有整个屏幕的截图screenshot,使用以下内容生成:
let layer = UIApplication.sharedApplication().keyWindow!.layer
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
layer.renderInContext(UIGraphicsGetCurrentContext())
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Run Code Online (Sandbox Code Playgroud)
我想裁剪它,以便不包括标签栏,我尝试使用以下代码:
let crop = CGRectMake(0, 0, //"start" at the upper-left corner
self.view.bounds.width, //include half the width of the whole screen
self.view.bounds.height + self.navigationController!.navigationBar.frame.height) //include the height of the navigationBar and the height of view
let cgImage = CGImageCreateWithImageInRect(screenshot.CGImage, crop)
let image: UIImage = UIImage(CGImage: cgImage)!
Run Code Online (Sandbox Code Playgroud)
此代码image仅显示屏幕的一小部分,从屏幕左上角开始的矩形(0,0),向右延伸不到屏幕宽度的一半,然后向下不到一半屏幕的高度.不过,我想要包括整个屏幕,除了标签栏占用的区域.有没有这种方法来裁剪它?
当我检测到我的锚点时,我添加了一个xib UIView文件作为我的SCNBox的材料但是当我解雇这个viewcontroller时,应用程序冻结,这是我的代码:
var detectedDataAnchor: ARAnchor?
var myView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
myView = (Bundle.main.loadNibNamed("ARViewOne", owner: nil, options: nil)![0] as? UIView)!
}
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
if self.detectedDataAnchor?.identifier == anchor.identifier {
let node = SCNNode()
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1,
chamferRadius: 0.0)
let imageMaterial = SCNMaterial()
imageMaterial.diffuse.contents = myView
box.materials = [imageMaterial]
let cube = SCNNode(geometry: box)
node.addChildNode(cube)
return node
}
return nil
}
@IBAction func back(_ sender: …Run Code Online (Sandbox Code Playgroud) 在我的应用程序内部运行时,我想将Xamarin Forms XAML页面呈现为图像。
这可能吗?
我知道我可以使用本机平台API来捕获屏幕,但是我想捕获所有信息,包括屏幕底部边界之外的所有信息。
为了澄清评论...
我没有截图。我需要能够将视图/页面的内容(包括用户需要滚动的地方)保存到图像中。
我正在尝试使用swift创建一个iOS应用程序,让用户可以拍照或从他们的图库中选择一个图像,并将其转换为可以保存到手机中的PDF文件.我的代码目前可以打开相机或图库并选择图像,但我无法将其转换为PDF格式.任何提示都会非常感谢,谢谢!
CameraViewController类
import UIKit
class CameraViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet weak var myImg: UIImageView!
@IBAction func takePhoto(_ sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
myImg.contentMode = .scaleToFill
myImg.image = pickedImage
}
picker.dismiss(animated: true, completion: nil)
}
@IBAction func savePhoto(_ sender: AnyObject) { …Run Code Online (Sandbox Code Playgroud) 你如何为 中的标题设置自定义字体UIContextualAction?
我试过了,UIAppearance但没有任何运气......
干杯! :)
uitableview ios uitableviewrowaction uiswipeactionsconfiguration uicontextualaction
我在做一个 CGImage
func otf() -> CGImage {
Run Code Online (Sandbox Code Playgroud)
这是渐变上的贝塞尔蒙版。所以,
// the path
let p = UIBezierPath()
p.moveTo etc
// the mask
let m = CAShapeLayer()
set size etc
m.path = p.cgPath
// the layer
let l = CAGradientLayer()
set colors etc
l.mask = m
Run Code Online (Sandbox Code Playgroud)
完成。所以然后UIImage以通常的方式渲染 a ......
UIGraphicsBeginImageContextWithOptions(sz.size, false, UIScreen.main.scale)
l.render(in: UIGraphicsGetCurrentContext()!)
let r = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
Run Code Online (Sandbox Code Playgroud)
但。然后要返回它,当然你必须转换为 CGImage
return r.cgImage!
Run Code Online (Sandbox Code Playgroud)
(如果您使用类似 ..
UIGraphicsImageRenderer(bounds: b).image { (c) in v.layer.render(in: c) }
Run Code Online (Sandbox Code Playgroud)
.. 你得到一个 UIImage,而不是一个 CGImage。)
似乎应该有更好/更优雅的方式 - 有没有办法更直接地“构建 …
如何设置自定义视图MKAnnotationView?我希望我的地图图钉通过UIView. 该UIView子类中可能有我想要自定义的其他视图。
网上有很多关于如何设置注释图像的示例,但没有如何实际更改该注释:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
{
if !(annotation is MKPointAnnotation) {
return nil
}
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier)
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView!.canShowCallout = true
}
else {
annotationView!.annotation = annotation
}
let pinImage = UIImage(named: "customPinImage")
annotationView!.image = pinImage
return annotationView
}
Run Code Online (Sandbox Code Playgroud) ios ×8
swift ×5
uikit ×2
uiview ×2
arkit ×1
c# ×1
cgimage ×1
mapkit ×1
objective-c ×1
pdf ×1
screenshot ×1
swift3 ×1
swift5 ×1
swiftui ×1
uiimageview ×1
uiscrollview ×1
uislider ×1
uiswipeactionsconfiguration ×1
uitableview ×1
view ×1
xamarin ×1
xcode ×1