2012-12-06 11 views
0

enter image description here我正在開發一款使用旋轉輪的iPad應用程序。我使用了鏈接http://www.raywenderlich.com/9864/how-to-create-a-rotating-wheel-control-with-uikit中給出的代碼。在這個我增加了旋轉車輪框架的大小。我用下面的代碼如何增加ios中旋轉輪的大小?

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]]; 
} 

我需要放大灰色圓圈直到外面的藍色圓圈。

+1

您還需要增加矩形大小和圖像。 –

+0

不是矩形。我需要增加輪子。所以在代碼中,我需要增加容器大小。我需要設置容器的框架 –

+0

@Umarajendran你指着藍色的外圈嗎? –

回答

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]; 
} 

現在這個調整大小的部分,以正確的尺寸得到一些幫助,

你可能要玩的價值,以獲得預期的效果。 您將遇到的問題是原始圖像的曲線,它會導致裁剪。 一個更好的方法可能會動態地繪製圖像,但我仍然在學習如何做到這一點我的自我。

+0

是的,我已經嘗試過,但我沒有得到我所期望的 –

+0

請參閱更新的答案 – Spriggsy

0

我通過增加扇區圖像的大小來解決此問題。現在我有一個大輪子。輪子是基於我們用於扇區的圖像的大小。感謝您的幫助