我被困在如何通過用戶單擊uibutton來移除uiview,立即加載場景的uibutton加載。烏布頓也沒有得到迴應。 我應該如何設置它?請幫助,非常感謝。以編程方式移除uiview by uibutton
- (void)viewWillAppear:(BOOL)animated {
UIView *holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, _imagePicker.selectedImage.size.width, _imagePicker.selectedImage.size.height)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:[holderView frame]];
[imageView setImage:_imagePicker.selectedImage];
[holderView addSubview:imageView];
UIButton *removeSticker = [UIButton buttonWithType:UIButtonTypeCustom];
removeSticker.frame = CGRectMake(0, 0, 200, 100);
[removeSticker setImage:[UIImage imageNamed:@"cancel-disabled.png"] forState:UIControlStateNormal];
[removeSticker addTarget:holderView action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[holderView addSubview: removeSticker];
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
[pinchRecognizer setDelegate:self];
[holderView addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[rotationRecognizer setDelegate:self];
[holderView addGestureRecognizer:rotationRecognizer];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[holderView addGestureRecognizer:panRecognizer];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[holderView addGestureRecognizer:tapRecognizer];
[parentPreviewView addSubview:holderView];
}
- (void) buttonClicked: (id)sender
{
[self.view removeFromSuperview];
}
很好的回答,假設原來的問題是關於刪除'holderView'。我會建議的一個建議是在'viewWillAppear:'方法上面移動'buttonClicked'方法*,特別是如果在.h接口文件中沒有聲明'buttonClicked'。 – 2012-01-03 18:42:46
@MichaelDautermann只要我們使用選擇器,我認爲'buttonClicked'方法定義在'viewWillAppear'的上面或下面並不重要。 – Hejazi 2012-01-03 18:48:29
感謝您的及時回覆,但是當我將其更改爲'[holderView removeFromSuperview];'時,它表示使用未聲明的標識符? – zeropt7 2012-01-03 18:54:20