【问题标题】:How to increase the wheel the size in rotating wheel in ios?如何在ios中增加旋转轮的大小?
【发布时间】:2018-02-07 20:46:22
【问题描述】:

我正在使用旋转轮开发一个 iPad 应用程序。我使用了此链接http://www.raywenderlich.com/9864/how-to-create-a-rotating-wheel-control-with-uikit 中给出的代码。在此我增加了旋转轮框尺寸。我使用了下面的代码

SMRotaryWheel *wheel = [[SMRotaryWheel alloc] initWithFrame:CGRectMake(0, 0, 400, 400)  
                                                andDelegate:self 
                                               withSections:8];

wheel.center = CGPointMake(400,300);
[self.view addSubview:wheel];

这会增加图像大小。用于旋转的轮子尺寸相同。我想将轮圈增大。我使用下面的代码来绘制轮子。请帮我做。

 - (void) drawWheel {
    container = [[UIView alloc] initWithFrame:self.frame];

    CGFloat angleSize = 2*M_PI/numberOfSections;

    for (int i = 0; i < numberOfSections; i++) {
        UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"segment.png"]];

        im.layer.anchorPoint = CGPointMake(1.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.alpha = minAlphavalue;
        im.tag = i;

        if (i == 0) {
            im.alpha = maxAlphavalue;
        }

        UIImageView *cloveImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
        cloveImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon%i.png", i]];
        [im addSubview:cloveImage];

        [container addSubview:im];
    }

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

    cloves = [NSMutableArray arrayWithCapacity:numberOfSections];

    UIImageView *bg = [[UIImageView alloc] initWithFrame:self.frame];
    bg.image = [UIImage imageNamed:@"bg.png"];
    [self addSubview:bg];

    UIImageView *mask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 58, 58)];
    mask.image =[UIImage imageNamed:@"centerButton.png"] ;
    mask.center = self.center;
    mask.center = CGPointMake(mask.center.x, mask.center.y+3);
    [self addSubview:mask];

    if (numberOfSections % 2 == 0) {

        [self buildClovesEven];
    } else {

        [self buildClovesOdd];
    }

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

我需要把灰色圆圈放大到外面的蓝色圆圈。

【问题讨论】:

  • 您还需要增加矩形大小和图像。
  • 不是矩形。轮子我需要增加。所以在代码中我需要增加容器的大小。我需要设置的容器框架
  • @Umarajendran 你指的是蓝色外圈吗?
  • 不增加戒指。我需要增加灰色段。

标签: ios rotation


【解决方案1】:

我不是专家,但这就是我的做法。请记住,我使用了一个标签,但它可以很好地调整大小。希望你能从中得到一些帮助

for (int i = 0; i < numberOfSections; i++) {
    UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"segment.png"]];
    im.frame = CGRectMake( 0 ,0, self.frame.size.width / 2.2,  M_PI * (container.frame.size.width   / numberOfSections) );
    im.layer.anchorPoint = CGPointMake(1.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;
    [container addSubview:im];
}

现在这会将部分调整为正确的大小,

您可能必须使用这些值来获得所需的效果。 您将遇到的问题是原始图像的曲线,它会导致剪辑。 更好的方法可能是动态绘制图像,但我仍在学习如何自己做。

【讨论】:

    【解决方案2】:

    我通过增加扇区图像的大小解决了这个问题。现在我有一个大轮子。轮子基于我们用于扇区的图像大小。感谢您的所有帮助

    【讨论】:

      猜你喜欢
      • 2015-02-21
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2023-04-10
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      相关资源
      最近更新 更多