gpt4 book ai didi

iphone - 在 UIView 转换、翻入或翻出时点击按钮

转载 作者:行者123 更新时间:2023-12-03 21:24:43 25 4
gpt4 key购买 nike

我儿子刚刚发现他可以点击我 View 的“完成”按钮,该按钮会翻转到上一个 View ,一次开始翻转,并在 View 转换(翻转)时点击一次或多次。第二次和下一次点击将再次触发相同的操作,从而创建一些有趣的结果,例如最终没有可见的 View ,但我的底层 UIWindow 。

我想我应该打电话:

[coming.view setUserInteractionEnabled: NO];
[going.view setUserInteractionEnabled: NO];

在涉及翻转过渡的两个 View 上,然后

[coming.view setUserInteractionEnabled: YES];

动画结束后的最终 View 。

我在想,也许比这更好的方法是在任何 View 转换时全局禁用点击。你怎么认为?

这是整个 View 切换代码:

- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2
{
/*
This method is called to switch views.
It flips the displayed view from the main view to the flipside view and vice-versa.
*/

UIViewController *coming = nil;
UIViewController *going = nil;
UIViewAnimationTransition transition;

[view1.view setUserInteractionEnabled: NO];
[view2.view setUserInteractionEnabled: NO];
if (view1.view.superview == nil) {
coming = view1;
going = view2;
transition = UIViewAnimationTransitionFlipFromLeft;
}
else {
coming = view2;
going = view1;
transition = UIViewAnimationTransitionFlipFromRight;
}
// coming.view.frame = [UIScreen mainScreen].applicationFrame;

// going.view.alpha = 1.0; //uncomment these lines if we want fading of views
// coming.view.alpha = 0.0;

NSArray *viewArray = [[NSArray alloc] initWithObjects:coming, going, nil];
[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[UIView beginAnimations:@"View Flip" context:viewArray]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

// coming.view.alpha = 1.0; //uncomment these lines if we want fading of views
// going.view.alpha = 0.0;

[UIView setAnimationTransition:transition forView:self.view cache:YES];
[self.view addSubview: coming.view];
}
[UIView commitAnimations];

}

- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
NSArray *viewArray = context;
[((UIViewController *)[viewArray objectAtIndex:1]).view removeFromSuperview];
[[viewArray objectAtIndex:1] viewDidDisappear:YES];
[[viewArray objectAtIndex:0] viewDidAppear:YES];
[[[viewArray objectAtIndex:0] view] setUserInteractionEnabled: YES];
[viewArray release];
}

最佳答案

set UserInteractionEnabled:似乎是要走的路。有异议吗?

关于iphone - 在 UIView 转换、翻入或翻出时点击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1370953/

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