gpt4 book ai didi

ios - 如何获取屏幕的结束CGPoint?

转载 作者:行者123 更新时间:2023-11-28 21:34:20 25 4
gpt4 key购买 nike

有没有办法找到屏幕的端点?假设屏幕大小为 (100x100),中点为 (50,),起点为 (0,),终点为 (100,)。我可以根据设备屏幕尺寸进行硬编码以获得终点,但基于假设,这将是一项过多的工作。

我正在制作一个基于 UIBezierPath 的自定义 UIView 动画。

这是我正在尝试做的事情:

enter image description here

如您所见,动画在到达某个点后停止。我希望这一点成为屏幕的末尾,以便 UIView 覆盖整个 屏幕。为了更清楚,我将 UIView 拖到 A 点,然后它动画到 B 点(终点,所以 B>A)

我不确定如何计算 B,所以当我将 UIView 拖到 A 时,它会动画到屏幕的末尾(屏幕的端点)。

为了更好的理解下面的代码:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.dragView];

if (touchLocation.x<250) {

if (!startBackSlide) {
_circleDragView.touchdragPoint=touchLocation.y;
_circleDragView.dragToPoint=CGPointMake(touchLocation.x+40, touchLocation.y);
[_circleDragView setNeedsDisplay];
_savedPoint=touchLocation;
}else{

//move the top and bot points backwards along with slide
[self animateCOmpleteBezier:touchLocation];

_circleDragView.touchdragPoint=touchLocation.y;
_circleDragView.dragToPoint=CGPointMake(touchLocation.x+54, touchLocation.y);
[_circleDragView setNeedsDisplay];
_savedPoint=touchLocation;

if (touchLocation.x<20) {
startBackSlide=NO;
snapped=YES;
}
}

}

if (touchLocation.x>=250) {

if (snapped) {
snapped=NO;
//move the top and bottom points to the specified point(In this case the end point)
}

}

}

-(void)animateCOmpleteBezier:(CGPoint) value{

[UIView animateWithDuration:0.01 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
_circleDragView.topWidthPoint=value.x-10;
_circleDragView.botWidthPoint=value.x-10;
[_circleDragView setNeedsDisplay];

} completion:^(BOOL finished) {

}];


}

最佳答案

屏幕的端点等于它的宽度和高度:

CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGPoint endPoint = CGPointMake(screenSize.width, screenSize.height);

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreen_Class/#//apple_ref/occ/instp/UIScreen/bounds

关于ios - 如何获取屏幕的结束CGPoint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34516275/

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