![](/img/trans.png)
[英]how do i detect UIButton's TouchUp event under UIView Gesture
[英]How do I release a parent UIView of/with a UIButton with parameters?
我想知道是否有一种释放UIView的方法,该方法通过subViews UIButton在特定功能之外不存在。 由于无法通过IBAction的按钮提供指向UIView的指针的参数,因此我陷入了困境。
- (IBAction)statsTemp1:(id)sender{
CGRect newSize = CGRectMake(0,13,322,434);
UIView *overl = [[UIView alloc] initWithFrame:newSize];
[self.view addSubview:overl];
[overl setBackgroundColor:[UIColor grayColor]];
[overl setAlpha:0.85];
[self doTheGraphIn:overl];
CGRect btnFrame = CGRectMake(150, 400, 30, 30);
UIButton *closeStatButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeStatButton.frame = btnFrame;
[overl addSubview:closeStatButton];
[closeStatButton addTarget:self action:@selector(closeStat:) forControlEvents:UIControlEventTouchUpInside];}-(IBAction)closeStat:(id)sender{
[self release];
}
-(IBAction)closeStat:(id)sender{
[overl release];
}
只是为了方便:我想用按钮释放(UIView *)覆盖,并且不能事先创建。
感谢您的帮助,我非常感激:)
听起来您想从self.view中删除over1。 (这意味着释放)
尝试一下...(从内存中,请检查)
- (IBAction)statsTemp1:(id)sender{
// Create UIView
CGRect newSize = CGRectMake(0,13,322,434);
UIView *overl = [[UIView alloc] initWithFrame:newSize];
[overl setBackgroundColor:[UIColor grayColor]];
[overl setAlpha:0.85];
[over1 setTag:99];
// Add UIButton to overl
CGRect btnFrame = CGRectMake(150, 400, 30, 30);
UIButton *closeStatButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeStatButton.frame = btnFrame;
[overl addSubview:closeStatButton];
[closeStatButton addTarget:self action:@selector(closeStat:) forControlEvents:UIControlEventTouchUpInside];
// Add overl to view
[self.view addSubview:overl];
// over1 can now be released because self.view has a pointer to it
[overl release];
// Do God knows what
[self doTheGraphIn:overl];
}
// Remove overl from self.view
-(IBAction)closeStat:(id)sender {
UIView *overl = [self.view viewForTag:99];
[over1 removeFromSuperView];
}
// The UIButton is autorelease, so you should be good.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.