请建议我,scrollview
一次又一次地重新绘制元素,而不是像 iOS 6 下的默认值一样旋转view
,这样是否很好。我的应用程序支持 iOS > 4.3。有一些方法可以scrollview
在此旋转和绘制元素。
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation];
[self didRotate:newOrientation];
[super viewDidLoad];
}
-(void)didRotate:(UIDeviceOrientation)orientation {
UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation];
CGRect frame = CGRectMake([UIScreen mainScreen].bounds.origin.x, [UIScreen mainScreen].bounds.origin.y, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
CGSize maximumSize;
if (UIInterfaceOrientationIsLandscape(newOrientation)) {
maximumSize = CGSizeMake(frame.size.width, frame.size.height);
} else {
maximumSize = CGSizeMake(frame.size.height, frame.size.width);
}
//self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView removeFromSuperview];
[name removeFromSuperview];
[text removeFromSuperview];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, maximumSize.width, maximumSize.height)];
self.scrollView.backgroundColor = [UIColor greenColor];
name = [self configureLabel:name WithCoordsOfX:100.0f y:10.0f Width:self.scrollView.bounds.size.width Height:10.0f forKey:@"title"];
text = [self configureLabel:text WithCoordsOfX:10.0f y:110.0f Width:self.scrollView.bounds.size.width-20 Height:self.scrollView.bounds.size.height forKey:@"text"];
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.size.width, text.frame.size.height+220);
text.backgroundColor = [UIColor grayColor];
// add myLabel
[self.scrollView addSubview:photo];
[self.scrollView addSubview:name];
[self.scrollView addSubview:text];
[self.view addSubview:self.scrollView];
NSLog(@"%f %f",self.scrollView.bounds.size.height,self.scrollView.bounds.size.width);
}
和
- (UILabel *)configureLabel:(UILabel *)label WithCoordsOfX:(float)x y:(float)y Width:(float)width Height:(float)height forKey:(NSString *)key
{
label = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
label.text = [personData valueForKey:key];
[label setNumberOfLines:0];
[label setFont:[UIFont fontWithName:@"Georgia" size:14.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor blackColor]];
[label sizeToFit];
return label;
}
我尝试使用这行代码,但它对我没有帮助。
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
其他人的观点也在之后旋转很酷
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
请告诉我是否有“好”的方法来改变方向UIScrollView
,或者重绘元素是最好的选择?任何这样的例子都会非常好。