首页 \ 问答 \ 将uiview呈现给uiimage的问题(Problems with rendering uiview to uiimage)

将uiview呈现给uiimage的问题(Problems with rendering uiview to uiimage)

所以我设置了一个UIImageView和一个Label,并将它们组合成一个UIView(如我这里显示的图片)

在此处输入图像描述

我做了以下操作将此视图呈现给UIImage,并分享它将带来UIActivityViewController。

  @IBOutlet var viewBack: UIView!
    @IBOutlet var dismissButton: UIButton!
    @IBOutlet var shareButton: UIButton!
    @IBOutlet var imageView: UIImageView!
    @IBOutlet var hello: UILabel!



    var image = UIImage()
    override func viewDidLoad() {
        super.viewDidLoad()
        shareButton.backgroundColor = UIColor.grayColor()
        shareButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
        shareButton.layer.cornerRadius = 10
        // Do any additional setup after loading the view.
        dismissButton.backgroundColor = UIColor.grayColor()
        dismissButton.layer.cornerRadius = 10
        viewBack.backgroundColor = UIColor(white: 1, alpha: 0.0)
        UIGraphicsBeginImageContextWithOptions(viewBack.bounds.size, viewBack.opaque, 0.0)
        viewBack.drawViewHierarchyInRect(viewBack.bounds, afterScreenUpdates: false)
        imageView.drawViewHierarchyInRect(imageView.frame, afterScreenUpdates: false)
        hello.drawViewHierarchyInRect(hello.frame, afterScreenUpdates: false)
        let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        print(snapshotImageFromMyView)
        image = snapshotImageFromMyView




    }
    @IBAction func dismiss(sender: AnyObject) {
        dismissViewControllerAnimated(true, completion: nil)
    }

    @IBAction func share(sender: AnyObject) {
        var shareArray : [AnyObject] = []
        shareArray.append(image)
        let activityVC = UIActivityViewController(activityItems: shareArray, applicationActivities: nil)
        if let popover = activityVC.popoverPresentationController{
            popover.sourceView = sender as? UIView
            popover.sourceRect = sender.bounds
        }

        self.presentViewController(activityVC, animated: true, completion: nil)
    }

所以viewBack是UIView包含两个子视图--UIImage和标签。 而且似乎是我正常设置所有渲染过程。 但是当我真正分享它时,结果真的很奇怪,一张黑色照片。 显然我将图像视图设置为特定图像,标签也不是空的。 我不知道这里有什么问题,希望有人可以帮助我。 提前致谢。 在此处输入图像描述


So I set up an UIImageView and a Label, and put them together to a single UIView(as my picture shown here)

enter image description here

And I did the following to render this view to an UIImage, and share it which will bring the UIActivityViewController.

  @IBOutlet var viewBack: UIView!
    @IBOutlet var dismissButton: UIButton!
    @IBOutlet var shareButton: UIButton!
    @IBOutlet var imageView: UIImageView!
    @IBOutlet var hello: UILabel!



    var image = UIImage()
    override func viewDidLoad() {
        super.viewDidLoad()
        shareButton.backgroundColor = UIColor.grayColor()
        shareButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
        shareButton.layer.cornerRadius = 10
        // Do any additional setup after loading the view.
        dismissButton.backgroundColor = UIColor.grayColor()
        dismissButton.layer.cornerRadius = 10
        viewBack.backgroundColor = UIColor(white: 1, alpha: 0.0)
        UIGraphicsBeginImageContextWithOptions(viewBack.bounds.size, viewBack.opaque, 0.0)
        viewBack.drawViewHierarchyInRect(viewBack.bounds, afterScreenUpdates: false)
        imageView.drawViewHierarchyInRect(imageView.frame, afterScreenUpdates: false)
        hello.drawViewHierarchyInRect(hello.frame, afterScreenUpdates: false)
        let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        print(snapshotImageFromMyView)
        image = snapshotImageFromMyView




    }
    @IBAction func dismiss(sender: AnyObject) {
        dismissViewControllerAnimated(true, completion: nil)
    }

    @IBAction func share(sender: AnyObject) {
        var shareArray : [AnyObject] = []
        shareArray.append(image)
        let activityVC = UIActivityViewController(activityItems: shareArray, applicationActivities: nil)
        if let popover = activityVC.popoverPresentationController{
            popover.sourceView = sender as? UIView
            popover.sourceRect = sender.bounds
        }

        self.presentViewController(activityVC, animated: true, completion: nil)
    }

So viewBack is the UIView contains two subviews- The UIImage and the label. And it seems to be that I set up all the rendering procedure normally. But when I actually share it, the result is really strange, a black picture. Apparently I set my image view to a specific image, and label isn't empty as well. I don't know what's wrong here, hopefully somebody could help me. Thanks in advance. enter image description here


原文:https://stackoverflow.com/questions/39324333
更新时间:2024-02-13 19:02

最满意答案

这已经在stackoverflow上得到了回答:

如何更改webservice url端点?


IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basically have two options.

Use the Binding Provider to set the endpoint URL

The first option is to change the BindingProvider.ENDPOINT_ADDRESS_PROPERTY property value of the BindingProvider (every proxy implements javax.xml.ws.BindingProvider interface):

...
EchoService service = new EchoService();
Echo port = service.getEchoPort();

/* Set NEW Endpoint Location */
String endpointURL = "http://NEW_ENDPOINT_URL";
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);

System.out.println("Server said: " + echo.echo(args[0]));
...

The drawback is that this only works when the original WSDL is still accessible. Not recommended.

Use the WSDL to get the endpoint URL

The second option is to get the endpoint URL from the WSDL.

...
URL newEndpoint = new URL("NEW_ENDPOINT_URL");
QName qname = new QName("http://ws.mycompany.tld","EchoService"); 

EchoService service = new EchoService(newEndpoint, qname);
Echo port = service.getEchoPort();

System.out.println("Server said: " + echo.echo(args[0]));
...

相关问答

更多
  • IMO,提供商告诉您更改服务端点(即哪里到达Web服务),而不是客户端端点(我不明白这可能是什么)。 要更改服务端点,您基本上有两个选项。 使用绑定提供程序设置端点URL 第一个选项是更改BindingProvider.ENDPOINT_ADDRESS_PROPERTY属性值(每个代理实现javax.xml.ws.BindingProvider接口): ... EchoService service = new EchoService(); Echo port = service.getEchoPort() ...
  • 如果您的Web服务将Agent元素定义为传入数据,那么就不可能将其解组为继承类。 我想有可能编写自己的编组,但它并不像听起来那么容易(我建议反对它)。 要么为每个类编写一个单独的WS(杂乱),要么使传入的数据具有可以存储其他结构的元素,例如type:any(也是凌乱的)。 事实是WS并不完全是OO。 If your webservice has Agent element defined as incoming data, then no it is not possible to unmarshall i ...
  • 我有很多错误需要解决。 我错过了要放在我使用Web服务的项目中的客户端jar文件,然后我需要使用WAS管理控制台指定JVM parameters 。 我把它放在了错误的地方。 -Djavax.net.ssl.trustStore=C:\IBM\RAD85\jdk\jre\lib\security\cacerts -Djavax.net.ssl.trustStorePassword=changeit I had a lot of errors to resolve. I was missing the c ...
  • 由于底层HTTP协议,Web服务默认是无状态的。 服务器将每个Web服务请求处理为新的交互,即使它来自同一客户端 通常,JAX-WS Web服务是无状态的:也就是说,您在Web服务对象中设置的局部变量和对象值都不会从一次调用保存到下一次。 甚至来自单个客户端的顺序请求也被视为独立的无状态方法调用。 存在Web服务用例,其中客户端可能希望在一次调用期间在服务上保存数据,然后在后续调用期间使用该数据。 例如,可以通过重复调用addToCart Web方法添加购物车对象,然后通过getCart Web方法获取。 ...
  • 这已经在stackoverflow上得到了回答: 如何更改webservice url端点? IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basic ...
  • Oracle Java 文档声明如下 创建并发布给定地址的指定实现者对象的端点。 必要的服务器基础架构将由JAX-WS实现使用一些默认配置来创建和配置。 由于JAX-WS是Java SE软件包的一部分,这意味着底层服务器取决于您正在运行程序的JVM的类型。 例如,在我的笔记本电脑上,我正在运行一个Java 8 OpenJDK,其中创建了一个“com.sun.net.httpserver.HttpServer”实例。 查找您的环境中启动的服务器的最快方法,只需跳到Endoint.java(实施)的(反编译)代 ...
  • 如果超时,看起来php无法正确解析WSDL URL。 您是否在WSDL Url上尝试过file_get_contents()/ curl? 也许尝试调用IP而不是localhost,看看它是怎么回事。 If it times out it looks like php isn't able to resolve the WSDL URL properly. Have you tried a file_get_contents()/curl on the WSDL Url? Maybe try calling ...
  • Web服务器 您称之为Web服务端点的只不过是在某个主机上侦听的Web服务器(通常为0.0.0.0)以及物理机或虚拟机上的某个端口,并对发送到该主机,端口和URI的HTTP请求进行响应。 Web服务器关心处理。 任何Web服务器本身都是应用程序或应用程序的静态或动态组件,如以下示例所示: JBoss,Glassfish,Tomcat等是应用程序,称为应用程序服务器,其中部署了实现Web服务器和相应端点的容器/ servlet /插件。 这些侦听某些端口,暴露通用Web服务器将请求路由到这些容器及其servl ...
  • 我已经解决了在app.config中的绑定标记中添加httpTransport的问题: 我必须在Visual Studio“服务引用”功能中添加服务引用。 尝试使用svcutil ,我得到另一个不同的异常。 I've solved the issue addi ...
  • 您是否尝试设置https代理而不是http代理? System.setProperty("https.proxyHost", "proxy ip"); System.setProperty("https.proxyPort", "port"); Did you try setting the https proxy, instead of http proxy? System.setProperty("https.proxyHost", "proxy ip"); System.setProperty("h ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)