這樣做的正確方法:
1-新建文件 - > UIView的 - >重命名爲addLinkQuestionView
2 - 新文件 - > OBJ C類 - >重命名爲addLinkQuestionView
現在u有一個廈門國際銀行,一.H和.M
3-轉到廈門國際銀行和文件的所有者選擇addLinkQuestionViewü步驟創建2
4-設計廈門國際銀行作爲您發佈的圖片鏈接,並連接起來,適當的網點addLinkQuestionView.h
5爲了您的UIView初始化中的.h這樣做:#進口 「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-然後在您的主視圖控制器添加此那就是像這樣呈現這樣的彈出是: A-導入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];
玩得開心!
你有什麼容器?一個UIViewController實例或一個帶.h和.m的xib? – Harris
請確保第二個代碼部分正在執行,同時通過放置一個斷點或一個'NSLog'來輕擊模糊區域 –
基本上,你想要的是在點擊背景時關閉帶有動畫的彈出窗口嗎? – Harris