gpt4 book ai didi

ios - 打开/关闭 View 作为菜单

转载 作者:行者123 更新时间:2023-11-29 01:39:33 26 4
gpt4 key购买 nike

我正在尝试执行打开和关闭 View (菜单)的效果,该 View 的原点为x = 55。打开效果正常效果不错,但是关闭效果有问题:效果从 x = 0 开始,而我的 View 在 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;
}

最佳答案

-(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)隐藏选择器{

if (isPickerShow) {

[UIView animateWithDuration:0.3 animations:^{

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

isPickerShow=NO;


}];

}

关于ios - 打开/关闭 View 作为菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32566058/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com