Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1115151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:06:54+00:00 2026-05-17T03:06:54+00:00

I am implementing a wheel for iPhone which should turn clockwise or anti-clockwise upon

  • 0

I am implementing a wheel for iPhone which should turn clockwise or anti-clockwise upon being dragged into that direction. Although it does this, there was some errors with smoothness. Sometimes it seems like it get confused regards which way it should turn. Any help please?

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

    NSSet *allTouches = [event allTouches];

    int len = [allTouches count]-1;

    UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
    CGPoint location = [touch locationInView:[self superview]];

    xfirst = location.x;
    xnext = xfirst;
    x = [NSNumber numberWithFloat:xfirst];
    yfirst = location.y;
    ynext = yfirst;
    y = [NSNumber numberWithFloat:yfirst];
    //NSLog(@"Touch began for wheel at %f and %f",xfirst, yfirst);
    //NSLog(@"Centre %f and %f",self.center.x, self.center.y);
}

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

    UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
    CGPoint location = [touch locationInView:[self superview]];

    xlast = location.x;
    ylast = location.y;

//dy / dx (gradient)
    if (((ylast-yfirst)/(xlast-xfirst) >= 0.3) || ((ylast-yfirst)/(xlast-xfirst) <= -0.3))
    {

    int seg1 = [self detectSegment:xnext :ynext];
    int seg2 = [self detectSegment:xlast :ylast];
    bool direction = [self isClockWise:seg1 :seg2];
    lastDirection = direction;

    float theAngle = [self getAngle:self.center.x:self.center.y:xfirst:yfirst:xlast:ylast];

    theAngle = theAngle / 6; 

    if (direction == YES)
    {

    }
    else {

        theAngle = -1*theAngle;
    }

    theAngle += totalRadians;   
    float rads = 6.28318531;
    int divAm = 0;
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setMaximumFractionDigits:0];
    [formatter setRoundingMode: NSNumberFormatterRoundDown];

    float nm = theAngle/rads;
    NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:nm]];
    [formatter release];
    divAm = [numberString floatValue];
    theAngle = theAngle - (float)(6.28318531*divAm);
    totalRadians = theAngle;
    xnext = xlast;
    ynext = ylast;
    [self rotateImage:theAngle];
    }
}


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

-(float) getAngle: (CGFloat)P1x: (CGFloat)P1y: (CGFloat)P2x: (CGFloat)P2y: (CGFloat)P3x: (CGFloat)P3y {
    float P23 = [self getLength:P2x:P2y:P3x:P3y];
    float P12 = [self getLength:P1x:P1y:P2x:P2y];
    float P13 = [self getLength:P1x:P1y:P3x:P3y];
    return acos((P23*P23 - P12*P12 - P13*P13)/(-2*P12*P13));
}

-(float) getLength: (CGFloat)P1x: (CGFloat)P1y: (CGFloat)P2x: (CGFloat)P2y
{
    return sqrt((P1x-P2x)*(P1x-P2x) + (P1y-P2y)*(P1y-P2y));
}

Any suggestions please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:06:55+00:00Added an answer on May 17, 2026 at 3:06 am

    I’m a bit confused why you’re using such a complex algorithm to find the angle. I don’t understand why you need the gradient, and using number formatting in a calculation is a little strange. That said, you may have good reason for doing these things, so I suggest you simplify the algorithm in order to test the rotation code; you can add the complexity later if you still need it. Fundamentally, you just need:-

    theAngle = atan2( location.y-self.center.y, location.x-self.center.x )

    to ensure the wheel tracks your finger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When implementing the Strategy Pattern, where does one put the code that determines which
Implementing custom DataAnnotationsModelMetadataProvider in ASP.NET MVC2. Assuming the object that is being rendered looks
Implementing a custom membership provider, there are certain properties such as MinRequiredPasswordLength that only
When programming in CDC I'm always reinventing the wheel, re-implementing stuff like Arrays.toString(Object[]) .
I am implementing a roulette wheel selection, and I would like to keep as
I'm enamoured with the idea of implementing my own single-entry-point gateway that does two
I have created a widget that is being hosted on a number of websites.
When implementing SuperBoxSelect (http://www.sencha.com/forum/showthread.php?69307-3.x-Ext.ux.form.SuperBoxSelect), I've realized that it currently does not support shift +
I'm looking for guidance on implementing a view that renders an NSAttributedString within a
Iam implementing facebook and twitter using sharekit for an iphone app. How can we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.