2013-04-06 89 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