Iphone 我怎样才能适应新环境?
我在ViewDidLoad中编写了如下代码Iphone 我怎样才能适应新环境?,iphone,orientation,Iphone,Orientation,我在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
// 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时,如何编写代码,它应该随之旋转…要启用旋转,您需要在视图控制器中实现以下方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
…支持所有方向。请注意,在iPhone上,您可能只希望支持3(iPhone上通常不支持倒立肖像),因此您可以根据需要返回YES
或NO
一旦实现了该方法,视图控制器现在应该根据方向更改进行旋转。但是,您的视图可能仍需要调整大小
为此,您可以在每个视图上使用自动调整大小的遮罩(以允许它们适当地拉伸/收缩或移动),或者通过实现
WillAnimateRotationInterfaceOrientation:duration:
方法手动调整它们的帧。前者通常是更好的方法,尽管在某些情况下,如果界面在横向上发生重大变化,您可能需要手动调整帧,或添加/删除整个视图。我尝试过,它可以工作,但退出速度非常慢,我看到许多程序工作速度非常快,我该怎么办?