iPhone中类似旋转拨号器的iRetro拨号器动画

iPhone中类似旋转拨号器的iRetro拨号器动画,iphone,ios,Iphone,Ios,我正在制作拨号器动画,比如iRetro手机应用程序动画 180度时,其不工作(未逆时针到达其原始位置)。 这是我的代码: - (void)viewDidLoad { [super viewDidLoad]; dialerImageView_Width = _dialer_View.bounds.size.width; dialerImageView_Height= _dialer_View.bounds.size.height; radians1 = atan2

我正在制作拨号器动画,比如iRetro手机应用程序动画

180度时,其不工作(未逆时针到达其原始位置)。 这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    dialerImageView_Width = _dialer_View.bounds.size.width;
    dialerImageView_Height= _dialer_View.bounds.size.height;

    radians1 = atan2f(_dialer_View.transform.b, _dialer_View.transform.a);

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

   UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation_Start = [touch locationInView:self.view];

    if (CGRectContainsPoint(_dialer_View.frame, touchLocation_Start)){
      startTouch_Angle = [self getAngle:touchLocation_Start];
    }
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation_moved = [touch locationInView:self.view];

    if (CGRectContainsPoint(_dialer_View.frame, touchLocation_moved)){
        MovedTouch_Angle = [self getAngle:touchLocation_moved];
        [_dialer_View setTransform:CGAffineTransformMakeRotation(startTouch_Angle-MovedTouch_Angle)];
    }
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation_End = [touch locationInView:self.view];
    if (CGRectContainsPoint(_dialer_View.frame, touchLocation_End)){
        EndTouch_Angle = [self getAngle:touchLocation_End];

// for < 180
        if ((180/M_PI * (startTouch_Angle - EndTouch_Angle)) > 0.0f  && (180/M_PI * (startTouch_Angle - EndTouch_Angle)) <= 180.0f )
        {
            [UIView animateWithDuration:0.5F animations:^{
                [_dialer_View setTransform:CGAffineTransformMakeRotation(radians1)];
            }];
        }

// > 180
        else  {
            [UIView animateWithDuration:0.5F animations:^{
                [_dialer_View setTransform:CGAffineTransformMakeRotation(- 180 + radians1)];
                //_dialer_View.transform = CGAffineTransformIdentity;
            }];![enter image description here][1]
        }
    }
}

-(CGFloat) getAngle: (CGPoint) touchLocation
{
    CGFloat x1 = _dialer_View.center.x;
    CGFloat y1 = _dialer_View.center.y; 
    CGFloat x2 = touchLocation.x;
    CGFloat y2 = touchLocation.y;
    CGFloat baseAngle = atan2((x2-x1),(y2-y1));
    return baseAngle;
}
-(void)viewDidLoad
{
[超级视图下载];
dialerImageView_Width=_dialer_View.bounds.size.Width;
dialerImageView_Height=_dialer_View.bounds.size.Height;
radians1=atan2f(_dialer\u View.transform.b,_dialer\u View.transform.a);
}
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint touchLocation_Start=[触摸位置视图:self.view];
如果(CGRectContainsPoint(_dialer_View.frame,touchLocation_Start)){
startTouch_Angle=[self-getAngle:touchLocation_Start];
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint touchLocation_moved=[触摸位置视图:self.view];
如果(CGRectContainsPoint(_dialer_View.frame,touchLocation_moved)){
MovedTouch_Angle=[self-getAngle:touchLocation_moved];
[_dialer_View setTransform:CGAffineTransformMakeRotation(开始接触角度移动触摸角度)];
}
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint touchLocation_End=[触摸位置视图:self.view];
如果(CGRectContainsPoint(_dialer_View.frame,touchLocation_End)){
EndTouch_Angle=[self getAngle:touch位置_End];
//小于180
如果((180/M_PI*(起始接触角-末端接触角))>0.0f&(180/M_PI*(起始接触角-末端接触角))180
否则{
[UIView动画宽度:0.5F动画:^{
[_dialer_View setTransform:CGAffineTransformMakeRotation(-180+弧度1)];
//_dialer_View.transform=CGAffineTransformity;
}];![在此处输入图像描述][1]
}
}
}
-(CGFloat)getAngle:(CGPoint)触摸位置
{
CGFloat x1=_拨号器_视图.center.x;
CGFloat y1=_dialer_View.center.y;
CGFloat x2=触摸位置.x;
CGFloat y2=触摸位置.y;
CGFloat基准角=atan2((x2-x1),(y2-y1));
返回基准角;
}

查看此示例代码和

-(void)handleObject:(NSSet*)触摸
withEvent:(UIEvent*)事件
isLast:(BOOL)lst
{
UITouch*touch=[[[event AllTouchs]AllObject]lastObject];
CGPoint curLoc=[触摸位置视图:self.view];
//NSLog(@“触摸圆1…”);
从角度浮动=atan2(第一个位置y-圆圈1IMGVW.中心y,
第一个位置x-圆圈1imgvw.center.x);
浮动角度=atan2(卷曲y-圆圈1imgVw.中心y,
卷曲度x-圆形1imgvw.中心x);
//所以旋转的角度是相对于我们当前的角度和
//手指移动的角度(从)
新角度=角度+(toAngle-fromAngle);
θ1=(新角度/M_π*180)+(新角度>0?0:360);
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event
{
[self-handleObject:TouchwithEvent:event isLast:YES];
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationDelegate:self];
[UIView设置动画持续时间:0.1];
[UIView设置动画曲线:UIViewAnimationCurveEaseIn];
新角度2=θ1*Mπ/180;
timer1=[NSTimer scheduledTimerWithTimeInterval:0.01目标:自选择器:@selector(handleTimer)userInfo:nil repeats:YES];
[UIView委员会];
}
-(IBAction)手持设备
{
新角度2-=0.05;
如果(新角度2<0)
{ 
//杀死计时器和动画将结束
[计时器1失效];
self.timer1=nil;
}
其他的
{
//NSLog(@“hadleTimer-newAngle2:%f…”,newAngle2);
//在这里,您可以定义要变换/旋转的视图-例如,circle1ImgVw
CGAffineTransform transform=CGAffineTransformMakeRotation(newAngle2);
circle1ImgVw.transform=变换;
}
}

您好,关于这一点,您能帮助我吗?我正在寻找相同的功能,并在google上查看了许多示例,但没有找到任何旋转拨号的示例,但找到了车轮旋转的示例。您能告诉我从何处开始吗。
-(void)handleObject:(NSSet *)touches 
      withEvent:(UIEvent *)event 
         isLast:(BOOL)lst 
{
UITouch *touch =[[[event allTouches] allObjects] lastObject];
CGPoint curLoc = [touch locationInView:self.view];

    //NSLog(@"Touched Circle 1 ...");

    float fromAngle = atan2( firstLoc.y-circle1ImgVw.center.y, 
                            firstLoc.x-circle1ImgVw.center.x );
    float toAngle = atan2( curLoc.y-circle1ImgVw.center.y, 
                          curLoc.x-circle1ImgVw.center.x );

    // So the angle to rotate to is relative to our current angle and the
    // angle through which our finger moved (to-from)
    newAngle = angle + (toAngle - fromAngle);

    theta_deg1 = (newAngle/M_PI*180) + (newAngle > 0 ? 0 : 360);
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
[self handleObject:touches withEvent:event isLast:YES];

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.1];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        newAngle2 = theta_deg1 * M_PI / 180;
        timer1 = [NSTimer scheduledTimerWithTimeInterval: 0.01 target: self selector:@selector(handleTimer) userInfo: nil repeats: YES];
        [UIView commitAnimations];

 }


-(IBAction)handleTimer
{
newAngle2 -= 0.05;

if (newAngle2 < 0) 
{ 
    //kill timer and animation will end
    [timer1 invalidate];
    self.timer1 = nil;


}
    else
    {
        //NSLog(@"hadleTimer - newAngle2: %f ...", newAngle2);

//here is where you define what view you want to transform / rotate - e.g. circle1ImgVw
        CGAffineTransform transform=CGAffineTransformMakeRotation(newAngle2);
        circle1ImgVw.transform = transform;
    }


}