我想在用户输入无效电子邮件时显示警告气泡。我可以成功显示气泡,但是如果方向改变气泡与 uitextfield 重叠,则气泡存在
以横向视图开始:
方向变成纵向:
其他方式:
以纵向视图开始:
方向变成风景(泡沫越走越远)
我的代码:
//image for warnings
//get screen size
CGRect screenRect = [[UIScreen mainScreen] bounds];
float bubleOriginx;
//detect device orientation
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation== UIInterfaceOrientationLandscapeRight)
{
bubleOriginx=screenRect.size.width*0.95;
}else
{
bubleOriginx=screenRect.size.width*0.72;
}
UIImage *bubble = [[UIImage imageNamed:@"create event button.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(15, 21, 15, 21)];
self.emailImage = [[UIImageView alloc] initWithImage:bubble];
self.emailImage.frame = CGRectMake(bubleOriginx, self.email.frame.origin.y+28, 0, 0);
UILabel *xlabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
xlabel.font = [UIFont fontWithName:@"Helvetica" size:15.0];
xlabel.text = string;
xlabel.numberOfLines = 0;
CGSize labelSize = [xlabel.text sizeWithFont:xlabel.font
constrainedToSize:xlabel.frame.size
lineBreakMode:xlabel.lineBreakMode];
xlabel.frame = CGRectMake(
xlabel.frame.origin.x, xlabel.frame.origin.y,
xlabel.frame.size.width, labelSize.height);
[xlabel setBackgroundColor:[UIColor clearColor]];
[self.emailImage addSubview:xlabel];
self.emailImage.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:self.emailImage];
[UIView animateWithDuration:0.85
animations:^(void) {
self.emailImage.frame = CGRectMake(bubleOriginx, self.email.frame.origin.y+28, 220, -60);
xlabel.frame = CGRectMake(10, 0, 210, 60);
} completion:^(BOOL finished) {
}];
我怎样才能稳定它UIImageview
,使它不会重叠?可以说它将始终与终点保持 +30 点的距离,uitextfield
或者至少不会重叠。
谢谢,莫德