繁体   English   中英

iPad中的轮播定位问题

[英]Carousel orientation issue in iPad

我刚刚开始担任iOS开发人员,目前正在为iPhone和iPad上实现的iOS应用程序开发自定义轮播功能。 我在iPad中遇到方向问题,当方向改变时,旋转木马会放错位置或消失。

以下是我编写的用于完成任务的代码行

-(void)initWithParentView:(UIView *)parentView{
    //identifying the size of the screen
    CGRect screenSize = [[UIScreen mainScreen]bounds];

    //based on the screen size i'm setting the position of the carousel  
    NavigationCarousel *selfCarousel = [super initWithFrame:CGRectMake(0.0, screenSize.size.height - 110, parentView.bounds.size.width, 55.0)];

    //this is the scroll view which will be added as a subview
    self.contentView = [[UIScrollView alloc] initWithFrame:CGRectMake(30, 0.0, 260, 55.0)];

    //adding the subview 
    [selfCarousel addSubview: self.contentView];
}

为了识别方向变化,我在调用about方法的类中编写了以下代码。

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(OrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

-(void)viewWillDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceBatteryLevelDidChangeNotification object:nil];
}

-(void)OrientationChange:(NSNotification*)notification{
    UIDeviceOrientation Orientation=[[UIDevice currentDevice]orientation];
    if(Orientation==UIDeviceOrientationLandscapeLeft || Orientation==UIDeviceOrientationLandscapeRight)
    {
        NSLog(@"Landscape");
        [self callTheClass];
    }
    else if(Orientation==UIDeviceOrientationPortrait)
    {
        NSLog(@"Portrait");
        [self callTheClass];
    }
}

-(void)callTheClass{
    self.carousel = [[NavigationCarousel alloc] initWithParentView:self.view];
    self.carousel.delegate = self;
}

调试时,我发现屏幕尺寸已按照iPad的方向进行了更新,但轮播未显示在标签上。 启动应用程序后,轮播会根据设备的方向显示,并在方向更改时消失。

更改方向后,iPad视图没有更新的原因可能是什么?

我强烈建议您使用“自动布局”,这将使您的开发人员的生活更加轻松。 有了自动版式,您会忘记这些问题:)有很多开源的自动版式框架,它们提供了覆盖功能。 我最喜欢的是:

他们有很好的文档和示例,希望您能很快学习它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM