1

我想在用户输入无效电子邮件时显示警告气泡。我可以成功显示气泡,但是如果方向改变气泡与 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或者至少不会重叠。

谢谢,莫德

4

1 回答 1

0

这是因为 autoResizingMask

    self.emailImage.autoresizingMask =  UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;

保持UIViewAutoresizingFlexibleRightMargin;(虽然不会像你期望的那样行事)

但是在方向更改上设置 origin.x 将解决它。

CGRect tempFrame = self.emailImage.frame;
tempFrame.origin.x = textField.frame.origin.x+textField.frame.size.width+30;
self.emailImage.frame = tempFrame;

适用于所有方向。假设 textField 是对您在图像中显示的 UITextField 的引用。

于 2013-02-28T15:58:11.543 回答