2013-06-20 69 views
2

所以,這似乎是一個奇怪的事件。我有一個帶有自定義背景圖像和隨機調用的動畫的UIButton(它是浮標來回擺動的圖像)。奇怪的是,只有按鈕的底部是可以點擊的。我有另一個按照設置方式完全相同的按鈕,您可以點擊圖像上的任意位置。UIButton只能部分點擊

背景圖片只是一個PNG(它具有透明度),但我創建的其他按鈕只要在邊界框內點擊即可使用。有任何想法嗎?

-(void)displayPauseButton 
{ 
    NSArray *pauseInfo = [self.sharedGameModel.theAssets objectForKey:@"buoy-ani"]; 

    // 
    // add mascot button 
    // aButtonArray has the info for a individual button in an array 
    // the buttons are read from the array in this order 
    // 0 array of images for the button animation triggered when clicked 
    // 1 x position 
    // 2 y position 

    // this array only has the names of the image animation 
    // so we init 
    NSArray *pauseImages = [pauseInfo objectAtIndex:0]; 
    UIImage *pauseImage = [UIImage imageNamed:[pauseImages objectAtIndex:0]]; 
    CGFloat theX=[[pauseInfo objectAtIndex:1] floatValue]; 
    CGFloat theY=[[pauseInfo objectAtIndex:2] floatValue]; 

    // create a new mutable array to fill with the actual object 
    // in the following loop 
    NSMutableArray *buttonAniImages = [[NSMutableArray alloc] init]; 
    for (id object in pauseImages) 
    { 
     [buttonAniImages addObject:[UIImage imageNamed:object]]; 
    } 

    // sets the custom image for the button 
    [self.pauseButton setImage:pauseImage forState:UIControlStateNormal]; 

    self.pauseButton.frame = CGRectMake(theX, theY, pauseImage.size.width, pauseImage.size.height); 
    self.pauseButton.imageView.animationImages = buttonAniImages; 

    self.pauseButton.imageView.animationDuration=3.0; 
    self.pauseButton.imageView.animationRepeatCount=1; 

    [self.gameScreen addSubview:self.pauseButton]; 

    // add the action associated with the button 
    [self.pauseButton addTarget:self action:@selector(someoneHitThePauseButton:) forControlEvents:UIControlEventTouchUpInside]; 
} 
+0

是您的按鈕框架大小正確嗎? – nielsbot

+1

是的,實際上只有兩種選擇 - 你在按鈕視圖之外繪圖,或者你的按鈕視圖有另一個視圖部分重疊。 – escrafford

+0

嘗試記錄self.gameScreen.bounds並檢查您的按鈕底部是否不在界限之外。 – Guferos

回答

1

Escrafford是對的。頂部有東西,只有它從來沒有明顯的頂部。我會添加我的經驗,以防其他人遇到同樣的問題。

在我的遊戲中,有多個UIViews有路徑動畫。他們的初始幀最初設置爲0,0,然後隨機調整路徑起點。但他們最初的框架覆蓋了按鈕的頂部。

感謝每一位提供反饋的人。