的問題是,您都出現了不止一個警報視圖。你的長按處理程序將被調用不同的狀態。
從文檔的UILongPressGestureRecognizer
:
長按手勢是連續的。當在指定的時間段(minimumPressDuration)按下允許的手指的數量(numberOfTouchesRequired)並且觸摸不超過允許的移動範圍(allowableMovement)時,手勢開始(UIGestureRecognizerStateBegan)。手指移動時,手勢識別器轉換到「更改」狀態,並且當任何手指擡起時手勢識別器結束(UIGestureRecognizerStateEnded)。
因此,您最終顯示「開始」狀態,然後是「已更改」狀態,並再次顯示「已結束」狀態的警報。如果你移動你的手指,你會得到一個「改變」狀態的流,你最終也會爲他們每個人顯示一個警報。
您需要確定何時實際希望顯示警報。你想讓它出現在第一個「改變」的狀態,或者當用戶舉起他們的手指,你得到「結束」的狀態。
你的代碼需要是這樣的:
- (IBAction)longPressDetected1:(UIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
// label1.text = @"Select Iran to observe its historical data projections ";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"Press the blue button (+) to select your region "
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}
當用戶提起他們的手指這將顯示警報。如果您希望在識別長按時立即顯示警報,請將UIGestureRecognizerStateEnded
更改爲UIGestureRecognizerStateChanged
。但請記住,由於長按可以生成多個「更改」狀態,因此您仍然可以獲得倍數。在這種情況下,您需要添加一個額外的檢查,以便只顯示警報,如果還沒有。
其實,這裏有一個簡單的方法來支持的「更改」狀態的單個警報:
- (IBAction)longPressDetected1:(UIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateChanged) {
sender.enabled = NO; // Prevent any more state updates so you only get this one
sender.enabled = YES; // reenable the gesture recognizer for the next long press
// label1.text = @"Select Iran to observe its historical data projections ";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"Press the blue button (+) to select your region "
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}
這與PHP有什麼關係? – Jodes 2013-03-09 03:56:20
對不起,這是ipad應用程序 – hooman 2013-03-09 04:13:06