我正在研究一個項目,我需要在一個圓上顯示9個按鈕,並且按下任何按鈕圓應該旋轉到顯示按鈕按下的指示器。如何在iOS中實現這一點?包含9個按鈕並在按鈕按下時旋轉的圓圈,iOS?
您的建議將不勝感激。請指教。
我正在研究一個項目,我需要在一個圓上顯示9個按鈕,並且按下任何按鈕圓應該旋轉到顯示按鈕按下的指示器。如何在iOS中實現這一點?包含9個按鈕並在按鈕按下時旋轉的圓圈,iOS?
您的建議將不勝感激。請指教。
讓我們試試這個
UIButton *button;
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
CABasicAnimation *halfTurn;
halfTurn = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
halfTurn.fromValue = [NSNumber numberWithFloat:0];
halfTurn.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
halfTurn.duration = 0.5;
halfTurn.repeatCount = HUGE_VALF;
[[button layer] addAnimation:halfTurn forKey:@"180"];
如果你真的想使用外部庫,那麼這可能是更好的選擇。我已經完成了使用旋轉木馬庫。請參考以下鏈接https://github.com/nicklockwood/iCarousel。這很容易,更好實施。您可以將按鈕視圖添加爲輪播視圖中的項目。
你想旋轉整個圓或只有特定的按鈕不清楚你的問題。如果你想旋轉圓整隻使用CALayer
動畫類實現this.Just設置按鈕框架,並與旋轉
我如何使用此旋轉圓形時尚按鈕? – 2013-05-10 09:50:55
你用過那個嗎?你必須爲此使用iCarouselTypeWheel。你不必爲旋轉做任何事情。你只需要給視圖組件。你必須使用[carousel scrollToItemAtIndex:animated: – 2013-05-10 10:03:31