gpt4 book ai didi

iphone - 使用增加的框架自动调整蒙版大小问题 - iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:10 25 4
gpt4 key购买 nike

我创建了一个 Diagonal UIView,在所有四个边的所有角和中心都有八个 subview 。

所有红点都可以拖动以调整菱形的大小。

所有 subview 在对角线 UIView 中添加一次,参见图像 Screen1.. enter image description here

现在我不想通过 Diamond View 的框架,所以它可以用中心和红点的框架来管理。我需要使用 Autoresizemask 进行管理,因此我不需要在增加或减少时传递每个时间范围。

这里是为菱形创建红点的代码..

 view4 = [[CustomDotRD alloc] initWithFrame:CGRectMake(self.frame.size.width - self.frame.size.width/4 - RED_W_H_RD/2, self.frame.size.height - self.frame.size.height/4 - RED_W_H_RD/2, RED_W_H_RD, RED_W_H_RD)];
view4.backgroundColor = [UIColor clearColor];
UIPanGestureRecognizer *panGestureDiamond = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(singleFingerTapsDiamond:)];
[view4 addGestureRecognizer:panGestureDiamond];
[panGestureDiamond release];
[view4 setContextPropertyColor:RGB_RED contextFrame:CGRectMake(RED_W_H/2, RED_W_H/2, RED_W_H, RED_W_H) index:4 tag:kTAG_D4];
view4.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
view4.center = CGPointMake(self.frame.size.width - self.frame.size.width/4, self.frame.size.height - self.frame.size.height/4);
[self addSubview:view4];
[self.boundDiamondArray addObject:view4];

我在这里发布了一些图片,同时增加了菱形,一些红点有奇怪的行为..

这里是在 Screen2 中看到的所有红点的所有自动调整大小掩码的列表。

1 - BottomMargin , LeftMargin , RightMargin
2 - TopMargin , BottomMargin , LeftMargin , RightMargin
3 - TopMargin , BottomMargin , LeftMargin
4 - TopMargin , BottomMargin , LeftMargin , RightMargin
5 - TopMargin , LeftMargin , RightMargin
6 - TopMargin , BottomMargin , LeftMargin , RightMargin
7 - TopMargin , BottomMargin , RightMargin
8 - TopMargin , BottomMargin , LeftMargin , RightMargin

enter image description here

四个角的红点工作正常..但是四个中心边缘的红点不能正常工作..让我展示一些屏幕..

enter image description here enter image description here

让我知道您解决这个问题的想法..

请记住,我不想传递任何框架或中心,只需使用 Autoresize Mask 进行管理。 .

了解 AutoresizeMask 的有用链接 Link .

问候,

最佳答案

由于红点的高度,边缘中心的点的 topMargin/bottomMargin 比率不正好为 3,因此自动调整大小对您不起作用。如果点的宽度和高度为零,它就会正确定位。

我认为实现 layoutSubviews 方法会是您任务的更好解决方案。

如果你真的想只使用 autoresizingMask 来解决这个问题。您需要将每个红点放在大小为零的 View 中,并将大小为零的 View 添加到菱形 View 中。使用下面的代码代替您提供的代码。您可能需要对其他部分进行一些更改,因为这些点不再是钻石的直接 subview 。

view4 = [[CustomDotRD alloc] initWithFrame:CGRectMake(-RED_W_H_RD/2, -RED_W_H_RD/2, RED_W_H_RD, RED_W_H_RD)];
view4.backgroundColor = [UIColor clearColor];
UIPanGestureRecognizer *panGestureDiamond = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(singleFingerTapsDiamond:)];
[view4 addGestureRecognizer:panGestureDiamond];
[panGestureDiamond release];
[view4 setContextPropertyColor:RGB_RED contextFrame:CGRectMake(RED_W_H/2, RED_W_H/2, RED_W_H, RED_W_H) index:4 tag:kTAG_D4];
UIView* dotView4 = [[CustomView alloc] initWithFrame:CGRectZero];
dotView4.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
dotView4.center = CGPointMake(self.frame.size.width - self.frame.size.width/4, self.frame.size.height - self.frame.size.height/4);
[dotView4 addSubview:view4];
[self addSubview:dotView4];
[dotView4 release];
[self.boundDiamondArray addObject:view4];

要解决触摸事件问题,您应该重写 CustomView 类中 UIViewpointInside:withEvent: 方法。以下代码将确保触摸事件到达 subview ,即使触摸点在 View 边界之外也是如此。

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
for(UIView* aView in self.subviews){
CGPoint localPoint = [self convertPoint:point toView:aView];
if([aView pointInside:localPoint withEvent:event]){
return YES;
}
}
return NO;
}

关于iphone - 使用增加的框架自动调整蒙版大小问题 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12216631/

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