4
我遇到以下問題。我有一個UIScrollView
,其上有幾個按鈕,圖標設置爲這些按鈕上的圖像。我有一個長按識別器連接到每個按鈕。如何在長按手勢時在發件人按鈕上顯示較小的刪除圖標?我的目標是創建當用戶想要刪除特定應用程序時由iOS提供的行爲。 這是一個按鈕的代碼(與圖像):長按手勢在UIButton中顯示圖像
//set the button with the image of conference here.
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(3, 3, w-5, h-5);
CALayer * l = [button layer];
[l setMasksToBounds:YES];
[l setCornerRadius:8.0];
[button setImage:thumb forState:UIControlStateNormal];
button.property = confInfo;
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
bView.tag = i;
//Add gesture recognizer to be used for deletion of conference.
UILongPressGestureRecognizer *pahGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizerStateChanged:)];
pahGestureRecognizer.minimumPressDuration = 1.0;
[button addGestureRecognizer:pahGestureRecognizer];
此代碼是在一個週期內(見我在代碼)。我的長按操作是這樣的:
- (void)longPressGestureRecognizerStateChanged:(UIGestureRecognizer *)gestureRecognizer {
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateEnded:
NSLog(@"Tapped!!!");
break;
default:
break;
}
}
如何我可以通過一個按鈕上我點擊這個動作,以顯示該按鈕的右上角小X的形象?
如果將突顯或選擇圖像與X的圖像,那麼你可以簡單地改變按鈕,而不是變化的圖像,這將是一個更好一點的狀態,而是取決於你是否是已經使用這些狀態圖像。 –
@ Fls'Zen:我對點擊事件有所瞭解,因此我想在長時間點擊時顯示一個小圖片。此外,我對這個按鈕是什麼也有一些看法,而帶有X的圖像實際上是一個帶有動作的按鈕。 –