【发布时间】:2014-08-02 18:22:36
【问题描述】:
我在 Xcode 中设计 UI 时遇到问题。
我以编程方式(当按下按钮时)创建了一个 UIImageView(黑色,透明覆盖)、UITextView(可编辑)和一个 UIButton 来清除这两个 UISubview。
这个问题都出现在模拟器和我的 iPhone 上。
这是我的代码
- (IBAction)openCommentTextView:(id)sender {
doneButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 40, 60, 35)];
doneButton.alpha = 0.0;
doneButton.layer.cornerRadius = 7;
doneButton.layer.borderColor = [[UIColor colorWithWhite:1.0 alpha:1.0] CGColor];
doneButton.layer.borderWidth = 3;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton setTitleColor:[UIColor colorWithWhite:1.0 alpha:1.0] forState:UIControlStateNormal];
doneButton.titleLabel.font = [UIFont fontWithName:@"AvenirNext-Regular" size:15];
[doneButton addTarget:self action:@selector(finishEditing:) forControlEvents:UIControlEventTouchUpInside];
commentTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 90, 280, 230)];
[commentTextView becomeFirstResponder];
commentTextView.alpha = 0.0;
if ([commentsTextViewViewer.text isEqual: @"Comment..."]) {
commentsTextViewViewer.text = @"";
} else {
commentTextView.text = commentsTextViewViewer.text;
}
commentTextView.keyboardAppearance = UIKeyboardAppearanceDark;
commentTextView.layer.cornerRadius = 7;
commentTextView.font = [UIFont fontWithName:@"GillSans" size:20];
commentTextView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.4];
backgroundOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 330, 568)];
backgroundOverlay.backgroundColor = [UIColor colorWithWhite:0.0 alpha:1.0];
backgroundOverlay.alpha = 0.0;
[self.view insertSubview:doneButton atIndex:11];
[self.view insertSubview:commentTextView atIndex:10];
[self.view insertSubview:backgroundOverlay atIndex:9];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
commentTextView.alpha = 1.0;
doneButton.alpha = 1.0;
[UIView commitAnimations];
[UIView setAnimationDuration:0.3];
backgroundOverlay.alpha = 1.0;
[UIView commitAnimations];
}
然而,不知何故,UIButton(doneButton) 和 UITextView(commentTextView) 在 UIImageView(黑色覆盖) 之下。 UIButton 和 UITextView 都会响应。 (我将 UIImageView(black overlay) alpha 设置为1.0,UIButton 和 UITextView 都没有出现,虽然都响应了)
原来是this(对不起,我无法将图片直接包含在此处...我没有足够的声誉)
但是当我复制这段代码并粘贴到一个新的单视图应用程序中时,它可以完美地工作,就像我希望的那样。 (like this)
我真的不知道为什么会发生这种情况......我已经在整个网络上搜索但没有成功。
这与 XCode 或我的 iPhone 本身有关吗?
如果有人能帮我解决这个问题,我会很高兴。
谢谢。
【问题讨论】:
标签: iphone objective-c uiimageview uibutton xcode5