我想将UIView转换为图像并将其保存在我的应用程序中.有人可以请告诉我如何截取视图的截图或将其转换为图像,以及将其保存在应用程序(不是相机胶卷)的最佳方法是什么?以下是视图的代码:
var overView = UIView(frame: CGRectMake(0, 0, self.view.frame.width/1.3, self.view.frame.height/1.3))
overView.center = CGPointMake(CGRectGetMidX(self.view.bounds),
CGRectGetMidY(self.view.bounds)-self.view.frame.height/16);
overView.backgroundColor = UIColor.whiteColor()
self.view.addSubview(overView)
self.view.bringSubviewToFront(overView)
Run Code Online (Sandbox Code Playgroud) 我有一个名为overView的UIView:
overView.frame = CGRectMake(self.view.frame.width/25, self.view.frame.height/25, self.view.frame.width/1.3, self.view.frame.height/1.2)
Run Code Online (Sandbox Code Playgroud)
我想仅截取此视图的屏幕截图,而不是整个屏幕.并制作尺寸截图:
(CGSizeMake(2480,3508 )
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(2480,3508 ), false, 0);
self.view.drawViewHierarchyInRect(CGRectMake(-self.view.frame.width/25, -self.view.frame.height/25,2480,3508), afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext()
Run Code Online (Sandbox Code Playgroud)
屏幕截图具有所需的大小,但它需要整个视图的屏幕截图,而不仅仅是"overView".
我的场景中有6个InputFields.他们的内容类型是十进制.
我从这些输入字段中获取值并检查它们的总和是否等于100.02.我在所有人中输入16.67.
float fireP = float.Parse(firePercentage.text);
float waterP = float.Parse(waterPercentage.text);
float lightP = float.Parse(lightPercentage.text);
float nightP = float.Parse(nightPercentage.text);
float natureP = float.Parse(naturePercentage.text);
float healthP = float.Parse(healthPercentage.text);
float total = fireP + waterP + lightP + nightP + natureP + healthP;
if (total == 100.02f)
{
Debug.Log("It's equal");
}
else
{
Debug.Log(" Not equal. Your sum is = " + total);
}
Run Code Online (Sandbox Code Playgroud)
我在控制台日志中得到"不等于.你的总和= 100.02".无论如何有任何想法为什么会发生这种情况?
我正在使用a UIImagePicker来向用户展示相机以拍摄将在应用中使用的照片.
我的问题是,当用户第一次打开图像选择器时,他们会看到一个提示:'"我的应用程序"想要使用两个选项访问您的相机,不允许和确定.
我的要求是,当用户单击"不允许"时,图像选择器将被关闭,留下黑色视图.有没有办法检测用户选择了不允许?
这是我的代码UIImagePicker:
var PhotoPicker:UIImagePickerController = UIImagePickerController()
PhotoPicker.delegate = self
PhotoPicker.sourceType = .Camera
PhotoPicker.cameraFlashMode = .Off
PhotoPicker.showsCameraControls = false
PhotoPicker.cameraDevice = .Rear
self.presentViewController(PhotoPicker, animated: false, completion: nil)
Run Code Online (Sandbox Code Playgroud) 我刚刚将我的统一更新为2018.1.0f2并且它给了我这个错误:"名称'UnityEditor.StandardEvents'的程序集已经存在(Packages/com.unity.standardevents/Editor/Editor.asmdef)"任何想法我应该是什么尽力避免这种情况.
这是我的示例JSON:
{"data":[{"id":141,"layoutLabel":"Sameer","hasCustomProb":1},
{"id":214,"layoutLabel":"abc","hasCustomProb":0}],"status":200}
Run Code Online (Sandbox Code Playgroud)
这是我上的课
[System.Serializable]
public class PlayerInfo
{
public string [] data;
public int status;
}
Run Code Online (Sandbox Code Playgroud)
这就是我从JSON获取“状态”的方法:
PlayerInfo P = JsonUtility.FromJson<PlayerInfo>(json);
Debug.Log(P.status) //returns 200
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗,我可以获取和保存数据数组,或者可以获取data.id和data.hasCustomProb吗?我是C#和团结的新手。
这可能看起来像一个noob问题,但我正在使用gamespark与团结.我正在这个包中发送vector2:
data.SetVector2(1, new Vector2(1.0f, 1.0f, 1.0f));
Run Code Online (Sandbox Code Playgroud)
我从数据包中得到它,如:
Vector2 a = _packet.Data.GetVector2 (1);
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:无法隐式转换类型UnityEngine.Vector2?到UnityEngine.Vector2.
在iPad Mini上显示内存警告后,我的应用程序应用程序崩溃.经过大量研究后,我发现问题是由于内存分配所致,UIImage( named:)例如:
SkipTutorial.image = UIImage(named: "skipTutorial.png")
Run Code Online (Sandbox Code Playgroud)
我应该使用contentsOfFile方法,以便不缓存图像.所以我用过:
if let imgPath = NSBundle.mainBundle().pathForResource("skipTutorial", ofType: "png") {
SkipTutorial.image = UIImage(contentsOfFile:imgPath)
}
Run Code Online (Sandbox Code Playgroud)
但是,这不会获取图像.图像位于Xcode 中的Images.xcassets中.基本上我的应用程序使用了许多不需要缓存的图像.我在这里发现了类似的问题:
甚至他的查询在如何使用contentsOfFile方法的评论中都没有得到答复.如果有人帮助我,我真的很感激.
我想从我的服务器获取视频并将其保存在我的资产中,以便稍后在我的游戏中查看。我知道使用 www. 但我不明白如何从我的服务器下载视频并给出它的网址。下面是获取视频作为纹理的代码。
var www = new WWW("http://Sameer.com/SampleVideo_360x240_2mb.mp4");
var movieTexture = www.movie;
Run Code Online (Sandbox Code Playgroud)
知道如何保存 mp4 文件吗?
我在鼠标单击时实例化一个对象。我需要将 x 和 y 转换位置最多保留 3 个小数位。这是我的代码。
void OnMouseDown()
{
ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit))
{
if(Input.GetKey(KeyCode.Mouse0))
{
GameObject obj=Instantiate(prefab,new Vector3(hit.point.x,hit.point.y,hit.point.z), Quaternion.identity) as GameObject;
OrbsList.Add(new Vector3(obj.transform.position.x,obj.transform.position.y,0));
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果 obj 在位置 (4.53325, 3.03369, 0) 处实例化,则将其保存为 (4.5,3.0,0)。我想将它的位置保存为 (4.53325, 3.03369, 0)。请帮忙谢谢。
var controllerScreen = UIImageView()
controllerScreen.backgroundColor = UIColor.redColor()
Run Code Online (Sandbox Code Playgroud)
这为UIImageView添加了红色不透明的颜色.我想添加透明的红色.有透明属性还是什么?
我有一个JsonString:
"baseAbilities":"[{"baseId":1,"name":"Focused Elemental Strike"}]"
Run Code Online (Sandbox Code Playgroud)
我想做到:
"baseAbilities":[{"baseId":1,"name":"Focused Elemental Strike"}]
Run Code Online (Sandbox Code Playgroud)
因此,JSON实用程序很容易对其进行反序列化.有什么建议
编辑:
这基本上是以下Json字符串中的json对象:
{"data":[{"id":9,"name":"Sam5","baseAbilities":"[{\"baseId \":1,\"name \":\"Focused Elemental Strike \"} {\ "了baseid \":9,\ "名称\":\ "清洗\"}]"]}
后端开发人员将JSON作为字符串保存在列baseAbilities中.现在我无法访问后端API.所以我需要将此字符串baseAbilities转换为JSON,以便我可以访问其中的对象.
现在我使用这些类来解码JSON:
[System.Serializable]
class GetBAResult
{
public List<bounceAbilityData> data;
}
[System.Serializable]
class bounceAbilityData
{
public int id;
public string name;
public string baseAbilities;
}
Run Code Online (Sandbox Code Playgroud)
这就是我解码JSON的方式:
GetBAResult P = JsonUtility.FromJson<GetBAResult>(w.text);
for (int i = 0; i < P.data.Count; i++)
{
Debug.Log(P.data[i].name);
GameObject layoutGroupNameButton = (GameObject)Instantiate(prefabBAButton);
layoutGroupNameButton.transform.SetParent(ParentPanel, false);
layoutGroupNameButton.GetComponentInChildren<Text>().text = P.data[i].name;
layoutGroupNameButton.GetComponent<BounceAbilityButton>().id = P.data[i].id;
layoutGroupNameButton.GetComponent<BounceAbilityButton>().name = P.data[i].name;
Debug.Log(P.data[i].baseAbilities);
}
Run Code Online (Sandbox Code Playgroud)
我需要在baseAbilities中获取内容,例如"baseID"和"name"
c# ×5
ios ×5
swift ×5
json ×2
screenshot ×2
uiview ×2
iphone ×1
uiimageview ×1
unityscript ×1
vector ×1
xcode ×1
xcode6 ×1