2012-07-10 54 views
0

我工作的一個應用程序,在那裏當我按下菜單鍵,IBAction爲創建一個具有覆蓋(添加子視圖)。這個子視圖必須保存必須可訪問的按鈕。我最初通過添加額外的按鈕到以前的觀點犯了一個錯誤。因此,當我按下菜單按鈕的新的覆蓋彈出與沒有被訪問的額外的按鈕。有什麼建議嗎?我是iOS編程的新手。謝謝添加一個新的視圖的視圖控制器 - iOS設備

- (IBAction) btnMoveTo:(id)sender 
{ 
UIButton* button= (UIButton*)sender; 

[self overlayCheck]; 

[movingButton setHidden:false]; 
[movingButton2 setHidden:false]; 
[movingButton3 setHidden:false]; 


[movingButton moveTo: 
CGPointMake(125,250) duration:0.8 
       option:curveValues[selectedCurveIndex]]; 

[movingButton2 moveTo: 
CGPointMake(25,250) duration:0.8 
       option:curveValues[selectedCurveIndex]]; 

[movingButton3 moveTo: 
CGPointMake(225,250) duration:0.8 
       option:curveValues[selectedCurveIndex]]; 

} 


-(void)overlayCheck{ 

CGRect frame = [homeButton frame]; 
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x - FrameSizeIncreaseAmount, frame.origin.y - FrameSizeIncreaseAmount, frame.size.width + FrameSizeIncreaseAmount * 2, frame.size.height + FrameSizeIncreaseAmount * 2)]; 
view.backgroundColor = [UIColor blackColor]; 


[self.view addSubview:view]; 


[UIView beginAnimations:@"fade in" context:nil]; 
[UIView setAnimationDuration:0.2]; 

[view setBackgroundColor:[[UIColor grayColor] colorWithAlphaComponent:MaxAlpha]]; 
[UIView commitAnimations]; 


} 

moveButton,movingButton2和movingButton3應該在新視圖上。覆蓋層不允許我訪問按鈕。

+0

你能告訴我們一些代碼嗎? – Aymarick 2012-07-10 09:51:04

+0

這可能是因爲你還沒有聯繫的按鈕到'IBAction'方法被後推調用。 – geminiCoder 2012-07-10 10:09:11

回答

0

不知道如果我理解正確,但你應該添加按鈕,您的覆蓋查看您在overlayCheck方法創建:

-(void)overlayCheck 
{ 
    CGRect frame = [homeButton frame]; 
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x - FrameSizeIncreaseAmount, frame.origin.y - FrameSizeIncreaseAmount, frame.size.width + FrameSizeIncreaseAmount * 2, frame.size.height + FrameSizeIncreaseAmount * 2)]; 
    view.backgroundColor = [UIColor blackColor]; 

    // --------------------------------------------- 
    // Becareful how you set the frame X-Y coordinate 
    // for your button if your moving buttons uses 
    // initWithFame:CGRectMake(X,Y,Width,Height); 
    // 
    // The X,Y are relative to the parent view 
    // that you add the moving buttons to 
    // --------------------------------------------- 
    [view addSubview:movingButton1]; 
    [view addSubview:movingButton2]; 
    [view addSubview:movingButton3]; 

    [self.view addSubview:view]; 


    [UIView beginAnimations:@"fade in" context:nil]; 
    [UIView setAnimationDuration:0.2]; 

    [view setBackgroundColor:[[UIColor grayColor] colorWithAlphaComponent:MaxAlpha]]; 
    [UIView commitAnimations]; 
} 
相關問題