2015-09-14 3 views
0

Я пытаюсь сделать эффект, чтобы открыть и закрыть представление (меню), которое имеет вид x = 55. открытый эффект работает должным образом хорошо, но близкий эффект имеет проблему: эффект начинается в x = 0 и мой взгляд на x = 55 ... тогда эффект кажется странным ....Открыть/закрыть представление как меню

Там мой код:

-(IBAction)menuClick:(id)sender { 
    if(!self.viewMais) { 
     CGRect screen = [[UIScreen mainScreen]bounds]; 
     self.viewMais = [[UIView alloc]initWithFrame:CGRectMake(55, 0, screen.size.width-55, screen.size.height)]; 
     [self.viewMais setBackgroundColor:[UIColor blackColor]]; 
     [self.view addSubview:self.viewMais]; 
     [self open]; 
    } 
    else { 
     [self close]; 
    } 

} 

    -(void)open { 
    CATransition *transition = [CATransition animation]; 
    transition.duration = 0.3; 
    transition.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionMoveIn; 
    transition.subtype = kCATransitionFromRight; 
    UIView *containerView = self.viewMais; 
    [containerView.layer addAnimation:transition forKey:nil]; 
} 

-(void)close { 
    CATransition *transition = [CATransition animation]; 
    transition.duration = 0.3; 
    transition.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionMoveIn; 
    transition.subtype = kCATransitionFromLeft; 
    UIView *containerView = self.viewMais; 
    [containerView.layer addAnimation:transition forKey:nil]; 
    [self performSelector:@selector(removerViewMais) withObject:nil afterDelay:0.3]; 
} 

-(void) removerViewMais { 
    [self.viewMais removeFromSuperview]; 
    self.viewMais = nil; 
} 

ответ

0

Я решил свою проблему с помощью следующего кода в тесном меню

-(void)close { 
CGRect destination = self.view.frame; 

[UIView animateWithDuration:0.25 animations:^{ 

self.viewMais.frame = CGRectMake(destination.size.width, self.viewMais.frame.origin.y, self.viewMais.frame.size.width, self.viewMais.frame.size.height); 

} completion:^(BOOL finished) { 
[self.viewMais setHidden:YES]; 
[self.viewMais removeFromSuperview]; 
self.viewMais = nil; 
}]; 
} 
1

- (IBAction) showPicker {

if (!isPickerShow) { 

    [self.view endEditing:YES]; 
     [UIView animateWithDuration:0.3 animations:^{ 

      viewWithPicker.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-viewWithPicker.frame.size.height, 320, 555); 
      isPickerShow=YES; 
     }]; 

} 

}

- (IBAction) hidePicker {

if (isPickerShow) { 

    [UIView animateWithDuration:0.3 animations:^{ 

      viewWithPicker.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height , 320, 255); 

      isPickerShow=NO; 


    }]; 

} 

}

Смежные вопросы