Watch (anchor Point)

Source: Internet
Author: User

//

Viewcontroller.m

Ui-no-37-1 Analogue Watch

//

Created by Wei Rong on 15/9/16.

Copyright (c) 2015 Wei Rong. All rights reserved.

//

#import "ViewController.h"

@interface Viewcontroller ()

{

Calayer *slayer; Seconds

Calayer *mlayer; Minute

Calayer *hlayer; Clockwise

}

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Dial

[Self addwatchface];

Seconds

[Self pointlayer];

Cadisplaylink *link = [Cadisplaylink displaylinkwithtarget:self selector: @selector (firetime)];

[link Addtorunloop:[nsrunloop Currentrunloop] formode:nsdefaultrunloopmode];

Timer Call pointer rotation

[Nstimer scheduledtimerwithtimeinterval:1 target:self selector: @selector (firetime) Userinfo:nil Repeats:yes];

}

Add a Dial

-(void) Addwatchface {

UIImage *image = [UIImage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:@ "dial" oftype:@ "PNG"];

Uiimageview *imageview = [[Uiimageview alloc] initwithimage:image];

Imageview.frame = CGRectMake (0, 0, IMAGE.SIZE.WIDTH/3, IMAGE.SIZE.HEIGHT/3);

Imageview.center = Self.view.center;

[Self.view Addsubview:imageview];

}

-(void) Pointlayer {

Second hand minute hand hour

UIImage *image = [UIImage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:@ "pointer" oftype:@ "PNG"];

SLayer = [[Calayer alloc] init];

Slayer.bounds = CGRectMake (0, 0, IMAGE.SIZE.WIDTH/8, IMAGE.SIZE.HEIGHT/4);

Slayer.position = Self.view.center;

Slayer.anchorpoint = Cgpointmake (0.5, 0.65);

Slayer.contents = (__bridge ID) (image. Cgimage);

[Self.view.layer Addsublayer:slayer];

Minute

Mlayer = [[Calayer alloc] init];

Mlayer.bounds = CGRectMake (0, 0, IMAGE.SIZE.WIDTH/7, IMAGE.SIZE.HEIGHT/5);

Mlayer.position = Self.view.center;

Mlayer.anchorpoint = Cgpointmake (0.5, 0.65);

Mlayer.contents = (ID) image. Cgimage;

[Self.view.layer Addsublayer:mlayer];

Clockwise

Hlayer = [[Calayer alloc] init];

Hlayer.bounds = CGRectMake (0, 0, IMAGE.SIZE.WIDTH/6, IMAGE.SIZE.HEIGHT/7);

Hlayer.position = Self.view.center;

Hlayer.anchorpoint = Cgpointmake (0.5, 0.65);

Hlayer.contents = (ID) image. Cgimage;

[Self.view.layer Addsublayer:hlayer];

}

Timer Call method

-(void) Firetime {

Nscalendar *calendar = [Nscalendar Currentcalendar];

Get the current time hour

Component:fromdate: Get a component from a date in the calendar

Nsinteger h =[calendar component:nscalendarunithour fromdate:[nsdate Date]];

NSLog (@ "%ld", (long) h);

Get current time score

Nsinteger m =[calendar component:nscalendarunitminute fromdate:[nsdate Date]];

Get current time seconds

Nsinteger s =[calendar component:nscalendarunitsecond fromdate:[nsdate Date]];

Slayer.transform = catransform3dmakerotation (m_pi/30*s, 0, 0, 1);

#warning wrong.

Mlayer.transform = catransform3dmakerotation (M_pi/30*m + (m_pi/(30*60)) *s, 0, 0, 1);

Hlayer.transform = catransform3dmakerotation (M_pi/6*h + (m_pi/(6*60)) *m, 0, 0, 1);

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end

Watch (anchor Point)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.