在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(0, 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(0, 67, self.view.frame.size.width, self.view.frame.size.height*0.07);
    }
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        segmentControl.frame  = CGRectMake(0, 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的源码,看一下对于数据的封装这一块是怎么做到的。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值