我想在用户输入无效的电子邮件时显示警告气泡。我可以成功地显示出泡沫,但同时存在气泡,如果方向改变泡沫与的UITextField重叠Uitextfield和UIImageView在方向更改时重叠
查看启动景观:
方向变为纵向:
其他各地方式:
查看开始为肖像:
方向变为横向(泡去更远)
我的代码:
//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
所以它不会重叠?让我们假设它始终保持距离终点uitextfield
+30点,或者至少不会重叠。
感谢, MORD
您使用的是iOS 6吗?在这种情况下,您可以使用自动布局约束来代替自动调整遮罩,这些遮罩更强大并且允许这种约束。 – 2013-02-28 15:33:19
不,这是5.1。应用程序必须兼容IOS 5.1及以上版本。 – 2013-02-28 15:35:42