gpt4 book ai didi

ios - 如何在 objective-c 中检查 UIView 是否为零

转载 作者:行者123 更新时间:2023-12-01 18:41:59 24 4
gpt4 key购买 nike

我是 iOS 新手,我在验证 View 方面遇到问题。我创建了类似签名的 View
How to draw Signature on UIView ,现在我想使用此代码进行验证

-(IBAction)SavebtnClick:(id)sender
{

if(drawSignView==nil)
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Pease Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow show];
}
else if (drawSignViewClient==nil)
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Please Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow show];
}
else
{

viewcontroller1 *management =[[viewcontroller1 alloc] initWithNibName:@"viewcontroller1" bundle:nil];
[self.navigationController pushViewController:management animated:YES];
}
}

但我没有成功。请告诉我我做错了什么。

enter image description here

我想做验证。

enter image description here

如果我没有签名,它会显示消息。

请给我建议。

提前致谢!

我保存图像和使用条件
UIGraphicsBeginImageContext(self.drawSignView.bounds.size);
[[self.drawSignView.layer presentationLayer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// NSData *postData = UIImageJPEGRepresentation(viewImage, 1.0);


// Store the data
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


NSData *imageData = UIImageJPEGRepresentation(viewImage, 100);
[defaults setObject:imageData forKey:@"image"];

[defaults synchronize];


if(viewImage==nil)
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Pease Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow setTag:1];
[alertviewshow show];
}

但它不起作用,因为它包含空白图像。

最佳答案

 UIGraphicsBeginImageContextWithOptions(self.drawSignView.bounds.size, NO, [UIScreen   mainScreen].scale);

[self.drawSignView drawViewHierarchyInRect:self.drawSignView.bounds afterScreenUpdates:YES];
UIImage *signImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

if(signImage)
{
//Get Image from sign view Succesfully
}
else
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Please Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow show];
}

试试这个代码它肯定有效。

关于ios - 如何在 objective-c 中检查 UIView 是否为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41518435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com