
正文
在ios8中做的屏幕旋转功能
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
http://www.cnblogs.com/smileEvday/archive/2013/04/24/Rotate2.html
思路出自这篇博主的文章。
直接上代码
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@"你旋转了");
if (toInterfaceOrientation ==UIInterfaceOrientationLandscapeLeft ) {
[self addSegmentControl:UIInterfaceOrientationLandscapeLeft];
[self.segementControl_base addTarget:self action:@selector(clickOnSegment:) forControlEvents:UIControlEventValueChanged];
[self initData];
[self initLrc]; }
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self addSegmentControl:UIInterfaceOrientationLandscapeRight];
[self.segementControl_base addTarget:self action:@selector(clickOnSegment:) forControlEvents:UIControlEventValueChanged];
[self initData];
[self initLrc]; }
else
{
[self addSegmentControl:UIInterfaceOrientationPortrait];
[self.segementControl_base addTarget:self action:@selector(clickOnSegment:) forControlEvents:UIControlEventValueChanged];
[self initData];
[self initLrc]; }
}
通过给对应的segment传入当前的旋转状态来设置segment在旋转到不同的方向时加载的数据
-(void)addSegmentControl:(UIInterfaceOrientation)toInterfaceOrientation
{
[self.segementControl_base removeFromSuperview];
NSArray *segmentArray = [NSArray arrayWithObjects:@"基本课文",@"应用课文" ,@"单词",nil];
UISegmentedControl * segmentControl = [[UISegmentedControl alloc]initWithItems:segmentArray];
self.segementControl_base = segmentControl;
#warning 判断旋转方式
if(UIInterfaceOrientationLandscapeLeft == toInterfaceOrientation){
segmentControl.frame = CGRectMake(, self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height*0.1);
}else if(toInterfaceOrientation == UIInterfaceOrientationPortrait){
segmentControl.frame = CGRectMake(, , self.view.frame.size.width, self.view.frame.size.height*0.07);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
segmentControl.frame = CGRectMake(, self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height*0.1);
}
segmentControl.selectedSegmentIndex = tags;
// [segmentControl addTarget:self action:@selector(onSegmentedControlChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentControl];
}
通过判断旋转方向来设置segment的大小,通过给不同的segment绑定不同的tags来确定相关的数据加载。
需要思考就是,全局变量是否应该使用的这么频繁。
接下来需要解决的问题就是音乐数据的打包和点击的时候切换到相关的事件点,就是监听cell的点击。
然后就看一下appsotre是否有一个推荐的功能,重复播放音乐的功能。
还有就是双语的功能,通过点击取消中文。随后就是看一些apple的源码,看一下对于数据的封装这一块是怎么做到的。






