我如何进行定向工作?
我已经在 ViewDidLoad 中进行了编码,如下所示。
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIColor *colorOne = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
UIColor *colorTwo = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
//Create the gradient and add it to our view's root layer
CAGradientLayer *gradientLayer = [[[CAGradientLayer alloc] init] autorelease];
gradientLayer.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[gradientLayer setColors:[NSArray arrayWithObjects:(id)colorOne.CGColor, (id)colorTwo.CGColor, nil]];
[self.view.layer insertSublayer:gradientLayer atIndex:0];
date1 = [[RRSGlowLabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 480)];
[date1 setTextAlignment:UITextAlignmentCenter];
date1.center = CGPointMake((self.view.frame.size.width/2)-20, (self.view.frame.size.height/2)-100);
date1.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
date1.font=[UIFont fontWithName:@"ds-digital" size:20.0];
//[label sizeToFit];
[date1 setBackgroundColor:[UIColor clearColor]];
date1.glowOffset = CGSizeMake(0.0, 0.0);
date1.glowColor = date1.textColor;
date1.glowAmount = 120.0f;
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
currentDate = [NSDate date];
//[dateFormatter setDateFormat:@"hh:mm"];
NSString *date = [dateFormatter stringFromDate:currentDate];
[self.date1 setText:date];
[self.view addSubview:date1];
time = [[RRSGlowLabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 480)];
[time setTextAlignment:UITextAlignmentCenter];
time.center = CGPointMake((self.view.frame.size.width/2)-20, self.view.frame.size.height/2);
time.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
time.font=[UIFont fontWithName:@"ds-digital" size:80.0];
//[label sizeToFit];
[time setBackgroundColor:[UIColor clearColor]];
time.glowOffset = CGSizeMake(0.0, 0.0);
time.glowColor = time.textColor;
time.glowAmount = 120.0f;
currentDate = [NSDate date];
[dateFormatter setDateFormat:@"hh:mm"];
date = [dateFormatter stringFromDate:currentDate];
[self.time setText:date];
[self.view addSubview:time];
seconds = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 480)];
[seconds setTextAlignment:UITextAlignmentCenter];
seconds.center = CGPointMake((self.view.frame.size.width/2)+105, (self.view.frame.size.height/2)+20);
seconds.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
seconds.font=[UIFont fontWithName:@"ds-digital" size:20.0];
currentDate = [NSDate date];
[dateFormatter setDateFormat:@"ss a"];
date = [dateFormatter stringFromDate:currentDate];
[seconds setText:date];
//[label sizeToFit];
[seconds setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:seconds];
date = nil;
dateFormatter = nil;
currentDate = nil;
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
}
简单来说,它将显示带有发光的当前时间,我想知道当我想要旋转 iphone 时如何编码,它应该随之旋转...
I have did coding as in ViewDidLoad as below
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIColor *colorOne = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
UIColor *colorTwo = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
//Create the gradient and add it to our view's root layer
CAGradientLayer *gradientLayer = [[[CAGradientLayer alloc] init] autorelease];
gradientLayer.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[gradientLayer setColors:[NSArray arrayWithObjects:(id)colorOne.CGColor, (id)colorTwo.CGColor, nil]];
[self.view.layer insertSublayer:gradientLayer atIndex:0];
date1 = [[RRSGlowLabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 480)];
[date1 setTextAlignment:UITextAlignmentCenter];
date1.center = CGPointMake((self.view.frame.size.width/2)-20, (self.view.frame.size.height/2)-100);
date1.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
date1.font=[UIFont fontWithName:@"ds-digital" size:20.0];
//[label sizeToFit];
[date1 setBackgroundColor:[UIColor clearColor]];
date1.glowOffset = CGSizeMake(0.0, 0.0);
date1.glowColor = date1.textColor;
date1.glowAmount = 120.0f;
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
currentDate = [NSDate date];
//[dateFormatter setDateFormat:@"hh:mm"];
NSString *date = [dateFormatter stringFromDate:currentDate];
[self.date1 setText:date];
[self.view addSubview:date1];
time = [[RRSGlowLabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 480)];
[time setTextAlignment:UITextAlignmentCenter];
time.center = CGPointMake((self.view.frame.size.width/2)-20, self.view.frame.size.height/2);
time.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
time.font=[UIFont fontWithName:@"ds-digital" size:80.0];
//[label sizeToFit];
[time setBackgroundColor:[UIColor clearColor]];
time.glowOffset = CGSizeMake(0.0, 0.0);
time.glowColor = time.textColor;
time.glowAmount = 120.0f;
currentDate = [NSDate date];
[dateFormatter setDateFormat:@"hh:mm"];
date = [dateFormatter stringFromDate:currentDate];
[self.time setText:date];
[self.view addSubview:time];
seconds = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 300, 480)];
[seconds setTextAlignment:UITextAlignmentCenter];
seconds.center = CGPointMake((self.view.frame.size.width/2)+105, (self.view.frame.size.height/2)+20);
seconds.textColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
seconds.font=[UIFont fontWithName:@"ds-digital" size:20.0];
currentDate = [NSDate date];
[dateFormatter setDateFormat:@"ss a"];
date = [dateFormatter stringFromDate:currentDate];
[seconds setText:date];
//[label sizeToFit];
[seconds setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:seconds];
date = nil;
dateFormatter = nil;
currentDate = nil;
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
}
In simple it will display the current time with glow on it, well I want to know that how can I code while i want to rotate iphone, it should rotate with it ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要启用旋转,您需要在视图控制器中实现以下方法:
...它将支持所有方向。请注意,在 iPhone 上您可能只想支持 3(iPhone 通常不支持颠倒纵向),因此您可以根据需要返回
YES
或NO
。一旦您实现了该方法,您的视图控制器现在应该旋转以响应方向变化。但是,您的视图可能仍需要调整大小。
为此,您可以在每个视图上使用自动调整大小蒙版(以允许它们适当地拉伸/收缩或移动),或者通过实现 willAnimateRotationToInterfaceOrientation:duration: 方法来手动调整其框架。前者通常是更好的方法,尽管在某些情况下,您可能需要手动调整框架,或者如果您的界面在景观方面发生重大变化,则需要添加/删除整个视图。
To enable rotation you need to implement the following method in your view controller:
...which would support all orientations. Note that on iPhone you may only want to support 3 (upside-down portrait is not typically supported on iPhone), so you can return
YES
orNO
as appropriate.Once you've implemented that method your view controller should now rotate in response to orientation changes. However, your view may still need to resize.
For this you can either use autoresizing masks on each view (to allow them to stretch/shrink or move as appropriate), or adjust their frames manually by implementing the
willAnimateRotationToInterfaceOrientation:duration:
method. The former is generally the better approach, although there will probably be some instances where you'll need to manually adjust frames, or add/remove entire views if your interface substantially changes in landscape.