问题描述
我是iphone新手。我正在做的是显示图片网格视图。我需要的是我必须从肖像模式将我的模拟器更改为横向模式。在旋转模拟器时,图像不会旋转。我怎么能与simulator.pls一起旋转图像为所有模式发布一些代码
hi i am new to iphone.what i am doing is displaying the images grid view. what i need is i have to change my simulator to landscape mode from portrait mode. while rotating the simulator the images are not rotated. how can i rotate images along with simulator.pls post some code for all mode
推荐答案
你必须设置,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
以便您可以获得所有类型的方向。最好根据方向重新定位控件。所以在屏幕上找到位置并将其设置为如下所示,
so that you can get all type of orientations. It's better to use reposition your controls according to the orientation. so find the location on screen and set it as given below,
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"login portrait");
okButton.frame = CGRectMake(69, 286, 72, 28);
cancleButton.frame = CGRectMake(178, 286, 72, 28);
usernameLabel.frame = CGRectMake(92, 140, 149, 16);
passwordLabel.frame = CGRectMake(129, 208, 75, 16);
usernameField.frame = CGRectMake(69, 164, 181, 31);
passwordField.frame = CGRectMake(69, 237, 181, 31);
mainLabel1.frame = CGRectMake(35, 58, 250, 21);
mainLabel2.frame = CGRectMake(35, 77, 153, 21);
[backgroundImage setImage:[UIImage imageNamed:@"portraitLogin.jpg"]];
} else {
NSLog(@"login landscape");
signinButton.frame = CGRectMake(190, 183, 86, 27);
cancleButton.frame = CGRectMake(309, 183, 86, 27);
usernameLabel.frame = CGRectMake(50, 100, 120, 21);
passwordLabel.frame = CGRectMake(50, 139, 75, 21);
usernameField.frame = CGRectMake(190, 95, 205, 31);
passwordField.frame = CGRectMake(190, 134, 205, 31);
mainLabel1.frame = CGRectMake(50, 58, 245, 19);
mainLabel2.frame = CGRectMake(295, 58, 153, 19);
[backgroundImage setImage:[UIImage imageNamed:@"landscapeLogin.jpg"]];
}
}
找到适合控制的地方,并在CGRectMake函数中指定。
Find right places for control and specify that in CGRectMake function.
也是所有控件,
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.usernameLabel = nil;
self.usernameField = nil;
self.passwordLabel = nil;
self.passwordField = nil;
self.okButton = nil;
self.cancleButton = nil;
self.backgroundImage = nil;
self.mainLabel1 = nil;
self.mainLabel2 = nil;
}
希望它适合你。
这篇关于如何改变横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!