纺车上的图标和文字应保持水平,不能随车轮旋转

时间:2013-01-06 23:42:13

标签: objective-c cocoa-touch user-interface rotation

我的应用程序中有一个旋转轮,分为八个部分。在每个部分中,将显示图像和文本。我的问题是图像是以截面的角度绘制的。即使角度不同,我希望图像和文本显得笔直。我正在使用下面的代码,我从a tutorial改编了它。

-(void)wheelForiPad
{
    UIImageView *bg = [[UIImageView alloc] initWithFrame:self.frame];
    bg.image = [UIImage imageNamed:@"patch_circle_normal.png"];
    [self addSubview:bg];

    CGFloat angleSize = 2*M_PI/numberOfSections;


    for (int i = 0; i < numberOfSections; i++)
    {

        UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sector.png"]];
        im.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
        im.layer.position = CGPointMake(container.bounds.size.width/2.0-container.frame.origin.x, 
                                        container.bounds.size.height/2.0-container.frame.origin.y); 
        im.transform = CGAffineTransformMakeRotation(angleSize*i);
        im.tag = i;

        if (i == 0)
        {
            selectedImgVw=[[UIImageView alloc] initWithFrame:CGRectMake(244, 20, 46, 213)];
            selectedImgVw.image=[UIImage imageNamed:@"yellow_highlight.png"];
            selectedImgVw.tag=22;
            [im addSubview:selectedImgVw];

        }

        UIImageView *cloveImage = [[UIImageView alloc] initWithFrame:CGRectMake(170, 80, 94, 94)];
        UIImage *image =[UIImage imageNamed:[iconsAry objectAtIndex:i]];
        cloveImage.image=image;
        [im addSubview:cloveImage];

        [container addSubview:im];


    }
    UIImageView *threadImgVw=[[UIImageView alloc] initWithFrame:CGRectMake(0, -5, 618, 620)];
    threadImgVw.image = [UIImage imageNamed:@"new_circle.png"];
    [self addSubview:threadImgVw];


}


 (void) drawWheel {

    container = [[UIView alloc] initWithFrame:self.frame];


    iconsAry=[[NSMutableArray alloc] init];


    if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
    {   [iconsAry addObject:@"transport_icon_iPhone.png"];
        [iconsAry addObject:@"sideways_icon_iPhone.png"];
        [iconsAry addObject:@"roadways_icon_iPhone.png"];
        [iconsAry addObject:@"streets_icons_iPhone.png"];
        [iconsAry addObject:@"environment_icons_iPhone.png"];
        [iconsAry addObject:@"public_safety_iPhone.png"];
        [iconsAry addObject:@"sanitation_icons_iPhone.png"];
        [iconsAry addObject:@"signal_icon_iPhone.png"];


        [self wheelForiPhone];
    }
    else
    {
        [iconsAry addObject:@"transport.png"];
        [iconsAry addObject:@"sideways_icon.png"];
        [iconsAry addObject:@"roadways_icon.png"];
        [iconsAry addObject:@"streets_icons.png"];
        [iconsAry addObject:@"environment.png"];
        [iconsAry addObject:@"public_safety.png"];
        [iconsAry addObject:@"sanitation_icons.png"];
        [iconsAry addObject:@"signal_icon.png"];

        [self wheelForiPad];

    }


    container.userInteractionEnabled = NO;
    [self addSubview:container];



    cloves = [NSMutableArray arrayWithCapacity:numberOfSections];



    if (numberOfSections % 2 == 0) {

        [self buildClovesEven];

    } else {

        [self buildClovesOdd];

    }

    [self.delegate wheelDidChangeValue:[self getCloveName:currentValue]];


}

此代码生成左侧的图像。我想在右边的图像中得到结果。我试图旋转,但是当我再次旋转滚轮时,图标会改变它的角度。

Current results Desired results

0 个答案:

没有答案