2013-04-06 93 views
1

我有一個名爲courseOptionsView的子視圖,我想在按鈕和特定條件下顯示和隱藏。當我使用滑動手勢時,視圖可以正常工作並且定位正確,但是當我使用另一個按鈕對該功能進行完全相同的調用時,它會重新定位它,但它會將其重新定位到原來的位置,而不是座標。發送。 :/我很難過。無法正確定位子視圖

*編輯 看來,當我++或 - 從cHNumber重置子視圖。有任何想法嗎?

IBOutlet UIView *courseOptionsView; 
- (IBAction)nextHole:(id)sender; 
- (IBAction)showCourseOptionsView:(id)sender; 
- (IBAction)hideCourseOptionsView:(id)sender; 


//show and hide functions 
-(void) showCourseOptions{ 
    if(activeRound){ 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     [UIView setAnimationDuration:1.0]; 
     [courseOptionsView setFrame:CGRectMake(50, 44, 200, 455)]; 
    } 
} 
-(void) hideCourseOptions{ 
    if(activeRound){ 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     [UIView setAnimationDuration:1.0]; 
     [courseOptionsView setFrame:CGRectMake(-200, 44, 200, 455)]; 
    } 
} 
// swipe calls 
- (IBAction)showCourseOptionsView:(id)sender { 
    [self showCourseOptions]; 
} 

- (IBAction)hideCourseOptionsView:(id)sender { 
    [self hideCourseOptions]; 
} 
//button call 
- (IBAction)nextHole:(id)sender 
{ 
    int totalStrokes = 0; 
    int totalPlusMinus = 0; 
    //[courseOptionsView setFrame:CGRectMake(0, 44, 200, 455)]; 
    //[self showCourseOptions]; 

    //save current hole 
    if(cHStrokes != [[currentRound objectForKey:[NSString stringWithFormat:@"hole%i",cHNumber]] intValue] || 
     cHPutts != [[currentRound objectForKey:[NSString stringWithFormat:@"hole%i_putts",cHNumber]] intValue]){ 
     [self saveCurrentHole]; 
    } 
    // calculate and display +/- and strokes 
    for (int i = 0; i < ([currentRound count]/2); i++){ 
     totalStrokes += [[currentRound objectForKey:[NSString stringWithFormat:@"hole%i",i+1]] intValue]; 
     totalPlusMinus += [[[selectedScoreCardData objectAtIndex:0] objectForKey:[NSString stringWithFormat:@"hole%i_par",i+1]] intValue]; 
    } 
    totalPlusMinus = totalStrokes - totalPlusMinus; 
    self.totalStrokesLabel.text = [NSString stringWithFormat:@"%i", totalStrokes]; 
    self.totalPlusMinusLabel.text = [NSString stringWithFormat:@"%i",totalPlusMinus]; 
     //set to next hole 
    /*------------------- 
    | SHOW VIEW HERE 
    --------------------*/ 
    if(cHNumber == 17){ 
     self.nextHoleButton.enabled = NO; 
     [self showCourseOptions]; 
    } 
    if(cHNumber == 1){ 
     self.prevHoleButton.enabled = YES; 
    } 
    cHNumber ++; 
    self.cHNumberLabel.text = [NSString stringWithFormat:@"%i", cHNumber]; 
    [self populateScoreCard]; 
    [strokePickerView reloadAllComponents]; 
    if(([currentRound count]/2) < cHNumber){ 

     [strokePickerView selectRow:cHStrokes - 1 inComponent:0 animated:YES]; 
     [strokePickerView selectRow:0 inComponent:1 animated:YES]; 
    }else{ 
     [strokePickerView selectRow:[[currentRound objectForKey:[NSString stringWithFormat:@"hole%i",cHNumber]] intValue] - 1 inComponent:0 animated:YES]; 
     [strokePickerView selectRow:[[currentRound objectForKey:[NSString stringWithFormat:@"hole%i_putts",cHNumber]] intValue] inComponent:1 animated:YES]; 
    } 
} 

回答

0

我想,也許在你放置視圖後,你正在調用另一個函數來再次改變佈局。一個可能的候選人是populateScoreCard