![](/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.