我有一个名为 courseOptionsView 的子视图,我想在某些条件下使用按钮显示和隐藏它。当我使用滑动手势时,视图可以正常工作并正确定位,但是当我使用另一个按钮对该函数进行完全相同的调用时,它会重新定位它,但它会将其重新定位到它所在的原始位置,而不是我所在的坐标发送。:/我很难过。
*edit 似乎当我 ++ 或 -- 从 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];
}
}