I want to show ContainerView's view controller as like this
我使用以下代码,它显示为我想要的
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.8];
if (_addLinkQuestionView.isHidden == YES)
{
_addLinkQuestionView.hidden = NO;
_addLinkQuestionView.alpha = 1.0;
}
else
{
_addLinkQuestionView.alpha = 0.0;
_addLinkQuestionView.hidden = YES;
}
[UIView commitAnimations];
但是点击模糊区域后,我想隐藏容器视图。那个区域是UIButton。我使用以下代码,但它什么也没做。
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.8];
_addLinkQuestionView.alpha = 0.0;
_addLinkQuestionView.hidden = YES;
[UIView commitAnimations];
任何帮助。提前完成。
答案 0 :(得分:0)
基本上,您似乎需要显示一个alertview行为,其中禁用了应用程序中的所有ui,同时仅启用了对话框中的内容。
或者,您可以使用MJPopupViewController或SLPopupViewController这样的库为您完成这项工作。
答案 1 :(得分:0)
正确的方法:
1-新文件 - > UIView - >将其重命名为addLinkQuestionView
2-新文件 - > obj c class - >将其重命名为addLinkQuestionView
现在你有一个xib,一个.h和一个.m
3-转到xib并在文件的所有者中选择您在步骤2中创建的addLinkQuestionView
4-将xib设计为您发布的图片链接,并将相应的出口链接到addLinkQuestionView.h
5-要在.h中初始化uiview,请执行以下操作: #import" addLinkQuestionView.h"
@implementation addLinkQuestionView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code.
[[NSBundle mainBundle] loadNibNamed:@"addLinkQuestionView" owner:self options:nil];
self.vuComplete.frame = CGRectMake(self.vuComplete.frame.origin.x, self.vuComplete.frame.origin.y, self.frame.size.width, self.frame.size.height);
[self addSubview:self.vuComplete];
self.vuContainer.layer.cornerRadius = 5.0;
self.vuContainer.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
self.vuContainer.layer.borderColor = [[UIColor clearColor]CGColor];
self.vuContainer.alpha = 0.0;
[self layoutIfNeeded];
}
return self;
}
-(void)awakeFromNib
{
}
- (IBAction)onBackgroundTapDismissView:(id)sender {
[UIView animateWithDuration:0.5
animations:^{self.vuContainer.alpha = 0.0;}
completion:^(BOOL finished){ }];
[self removeFromSuperview];
}
注意: - (IBAction)onBackgroundTapDismissView可以通过在你的addLinkQuestionView的灰色背景uiview上删除uitapgesturerecognizer来实现,这样点击它就可以解除整个uiview(vuComplete)
6-然后在你的主视图控制器中添加这个,弹出如下: 首先导入addLinkQuestionView.h B-将此代码添加到您为了呈现addLinkQuestionView而单击的按钮操作上: addLinkQuestionView * popup = [[addLinkQuestionView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
[UIView animateWithDuration:0.25
animations:^{popup. addLinkQuestionView.alpha = 1.0;}
completion:^(BOOL finished){ }];
[self.view addSubview:popup];
玩得开心!