Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › XCode/Objective C Clock
New Posts  All Forums:Forum Nav:

XCode/Objective C Clock

post #1 of 2
Thread Starter 
Hi. I'm trying to make an iPhone app to learn. I'm trying to make a simple analog clock in XCode (uses Objective C). I tried my hand at it but I've encountered a problem. How do I set the rotation point on the hand?

Here is my code so far from the .m file.
Code:
@implementation ClockViewController
- (void) viewDidAppear:(BOOL)animated {
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
[NSTimer scheduledTimerWithTimeInterval:1.0
 target:self
   selector:@selector(updateTime:)
   userInfo:nil
repeats:YES];
}

- (void)updateTime {
currentTime = [NSDate date];
dateComponents = [calendar components:unitFlags fromDate:currentTime];
hour = [dateComponents hour];
minute = [dateComponents minute];
second = [dateComponents second];
hourAngle = (30 * hour + minute / 2);
minAngle = (6 * minute);
minuteHand.transform = CGAffineTransformMakeRotation(minAngle * M_PI / 180);
hourHand.transform = CGAffineTransformMakeRotation(hourAngle * M_PI / 180);
}

From the .h file:
Code:
@interface ClockViewController : UIViewController {
    IBOutlet UIImageView *hourHand;
    IBOutlet UIImageView *minuteHand;
    
    NSDate *currentTime;
    NSDateComponents *dateComponents;
    
    NSCalendar *calendar;
    NSCalendarUnit unitFlags;
    
    NSTimer *updateTimer;
    NSString *seconds;
    int minute, hour, second;
    int minAngle, hourAngle;
}


EDIT: Nevermind, good for now.
Edited by Domele - 2/12/11 at 2:23pm
First Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD x3 425 OCed @ 3.6 GHz Gigabyte MA78LM-S2 MSI GTX 460 Cyclone 768 MB 2 GB 
Hard DriveOSMonitorKeyboard
Hitachi 1 TB 7200 RPM Windows 7 Ultimate 32 Bit Emprex 22" 1680x1050 Standard Compaq Keyboard 
PowerCaseMouse
Thermaltake 650 Watt Coolermaster CM 690 Logitech G5 
  hide details  
Reply
First Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD x3 425 OCed @ 3.6 GHz Gigabyte MA78LM-S2 MSI GTX 460 Cyclone 768 MB 2 GB 
Hard DriveOSMonitorKeyboard
Hitachi 1 TB 7200 RPM Windows 7 Ultimate 32 Bit Emprex 22" 1680x1050 Standard Compaq Keyboard 
PowerCaseMouse
Thermaltake 650 Watt Coolermaster CM 690 Logitech G5 
  hide details  
Reply
post #2 of 2
Thread Starter 
Anyone know how I would go about obtaining multiples times for different timezones efficiently? (EST, PST, MST, etc.)
First Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD x3 425 OCed @ 3.6 GHz Gigabyte MA78LM-S2 MSI GTX 460 Cyclone 768 MB 2 GB 
Hard DriveOSMonitorKeyboard
Hitachi 1 TB 7200 RPM Windows 7 Ultimate 32 Bit Emprex 22" 1680x1050 Standard Compaq Keyboard 
PowerCaseMouse
Thermaltake 650 Watt Coolermaster CM 690 Logitech G5 
  hide details  
Reply
First Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD x3 425 OCed @ 3.6 GHz Gigabyte MA78LM-S2 MSI GTX 460 Cyclone 768 MB 2 GB 
Hard DriveOSMonitorKeyboard
Hitachi 1 TB 7200 RPM Windows 7 Ultimate 32 Bit Emprex 22" 1680x1050 Standard Compaq Keyboard 
PowerCaseMouse
Thermaltake 650 Watt Coolermaster CM 690 Logitech G5 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › XCode/Objective C Clock