ios - 由于添加了文本字段,警报 View 向上移动

标签 ios

我正在通过单击按钮创建警报 View 。我在其中放置了一个 UITextfield。但警报 View 在屏幕中向上移动。我无法将其带回屏幕中央。

这是我的代码和屏幕截图。
enter image description here

创建此警报 View 的代码是这样的:-

- (IBAction)btn_cancelAppointment_click:(id)sender
{
    // Here We are Creating Alertview which asks for
    UIAlertView* cancelAlert = [[UIAlertView alloc] init];

    [cancelAlert setDelegate:self];
    [cancelAlert setTitle:@"Are you sure you want to request cancellation of this appointment?"];
    [cancelAlert setMessage:@"                             "];
    [cancelAlert addButtonWithTitle:@"NO"];
    [cancelAlert addButtonWithTitle:@"YES"];

    UITextField * txt_cancelNote = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 88.0, 245.0, 30.0)];

    [txt_cancelNote setBackgroundColor:[UIColor whiteColor]];
    [txt_cancelNote setBorderStyle:UITextBorderStyleRoundedRect];
    [txt_cancelNote setPlaceholder:@"Enter cancellation note"];
    txt_cancelNote.tag = 11;

    [cancelAlert addSubview:txt_cancelNote];
    cancelAlert.delegate = self;
    [cancelAlert show];
}

所以,如果有人能告诉我如何将其带回屏幕中央。任何帮助将不胜感激。

最佳答案

尝试设置UIAlertViewtransform属性

  UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Test" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  alertView.transform = CGAffineTransformMakeTranslation(x, y);

关于ios - 由于添加了文本字段,警报 View 向上移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17170296/

相关文章:

ios - 使用 += 表达式初始化字符串返回 "()"

ios - OCMock stub block

ios - Restkit 删除 Coredata 中没有出现在 JSON 中的对象

ios - Parse Cocoapod 破坏本地化

ios - 在 UITabBarController 之前呈现登录 View Controller

javascript - 我正在尝试将图像添加到选项卡栏项目但未加载

iphone - 使用 'tap-to-focus' 和曝光控制的 GPUImage 视频捕获

ios - SceneKit 添加地板崩溃

iphone - 当我使用 CPTPGraphHostingView [核心图] 时,背景 ImageView 是颠倒的(翻转)

ios - xcode 6 自定义标签栏在选择图像之前不显示图像