gpt4 book ai didi

ios - 如何知道一个 View 是否触及 Ios 中的其他 View

转载 作者:行者123 更新时间:2023-11-29 12:06:19 28 4
gpt4 key购买 nike

我想知道我的 View 何时在任何位置相互接触 This Is Image That Give You Better Idea About The My Proble

提前致谢。

最佳答案

您可以为此使用 UIKit Dynamics。在您的 viewController 中添加以下行。

UIDynamicAnimator* animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];

UICollisionBehavior* collision = [[UICollisionBehavior alloc] initWithItems:@[view1]];


[animator addBehavior:collision];

// add a boundary that coincides with the top edge
CGPoint topEdge = CGPointMake(view2.frame.origin.x +
view2.frame.size.width, view2.frame.origin.y);

[collision addBoundaryWithIdentifier:@"view2"
fromPoint:view2.frame.origin
toPoint:topEdge];

现在在您的 View Controller 中添加此委托(delegate) UICollisionBehaviorDelegate并设置 collision.collisionDelegate = self;

您可以通过以下方法获取碰撞通知

- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item 
withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p {
NSLog(@"Boundary contact occurred - %@", identifier);
}

关于ios - 如何知道一个 View 是否触及 Ios 中的其他 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34869687/

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