0
내 코드에 2 가지 문제가 있으며 누군가 내가 문제 해결을 도울 수 있는지 알고 싶습니다. 내가 원하는 objective-c가있는 무한 회전식 컨베이어
#import "ViewController.h"
@interface ViewController() {
@private NSInteger index;
@private NSInteger iterations;
@private UIButton* buttons[6];
@private CGPoint centers[6];
@private CGRect bounds[6];
@private CGFloat opacities[6];
@private CGFloat opacitieOffsets[6];
@private CGPoint centerOffsets[6];
@private CGRect boundOffsets[6];
@private NSString* titles[6];
}
@property (strong, nonatomic) NSTimer *timer;
@end
@implementation ViewController
@synthesize Button1;
@synthesize Button2;
@synthesize Button3;
@synthesize Button4;
@synthesize Button5;
@synthesize Button6;
@synthesize TitleLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
buttons[0] = Button1;
titles[0] = @"btnTitle1";
buttons[1] = Button2;
titles[1] = @"btnTitle2";
buttons[2] = Button3;
titles[2] = @"btnTitle3";
buttons[3] = Button4;
titles[3] = @"btnTitle4";
buttons[4] = Button5;
titles[4] = @"btnTitle5";
buttons[5] = Button6;
titles[5] = @"btnTitle6";
for (NSInteger i = 0; i < 6; i++)
{
centers[i] = buttons[i].center;
bounds[i] = buttons[i].bounds;
opacities[i] = buttons[i].alpha;
}
}
- (void)viewDidUnload
{
[self stopAnimation];
[self setButton1:nil];
[self setButton2:nil];
[self setButton3:nil];
[self setButton4:nil];
[self setButton5:nil];
[self setButton6:nil];
[self setTitleLabel:nil];
[super viewDidUnload];
}
/////////////////////////////////////////////////////
- (IBAction)swipeLeft:(UISwipeGestureRecognizer *)sender {
[self stopAnimation];
buttons[index].enabled = NO;
{
TitleLabel.text = @"";
index = [self next:index];
[self startAnimation];
}
}
- (IBAction)swipeRight:(UISwipeGestureRecognizer *)sender {
[self stopAnimation];
buttons[index].enabled = NO;
{
TitleLabel.text = @"";
index = [self back:index];
[self startAnimation];
}
}
///////////////////////////////////////////////////
- (void)startAnimation
{
[self prepareForUpdate];
[self.timer invalidate];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(update) userInfo:nil repeats:YES];
}
- (void)stopAnimation
{
[self.timer invalidate];
[self finalizeUpdate];
self.timer = nil;
}
- (void)prepareForUpdate
{
NSInteger i = 0;
NSInteger iter = index;
do
{
centerOffsets[iter] = CGPointMake
(
(centers[i].x - buttons[iter].center.x)/30,
(centers[i].y - buttons[iter].center.y)/30
);
boundOffsets[iter] = CGRectMake
(
(bounds[i].origin.x - buttons[iter].bounds.origin.x)/30,
(bounds[i].origin.y - buttons[iter].bounds.origin.y)/30,
(bounds[i].size.width - buttons[iter].bounds.size.width)/30,
(bounds[i].size.height - buttons[iter].bounds.size.height)/30
);
opacitieOffsets[iter] = (opacities[i] - buttons[iter].alpha)/30;
i++;
iter = [self next:iter];
}
while (iter != index);
iterations = 30;
}
- (void)update
{
if (iterations <= 1)
{
}
if (iterations > 0)
{
for (NSInteger i = 0; i < 6; i++)
{
buttons[i].center = CGPointMake
(
centerOffsets[i].x + buttons[i].center.x,
centerOffsets[i].y + buttons[i].center.y
);
buttons[i].bounds = CGRectMake
(
boundOffsets[i].origin.x + buttons[i].bounds.origin.x,
boundOffsets[i].origin.y + buttons[i].bounds.origin.y,
boundOffsets[i].size.width + buttons[i].bounds.size.width,
boundOffsets[i].size.height + buttons[i].bounds.size.height
);
buttons[i].alpha = buttons[i].alpha + opacitieOffsets[i];
}
iterations--;
}
else [self stopAnimation];
}
- (void)finalizeUpdate
{
NSInteger i = 0;
NSInteger iter = index;
do
{
buttons[iter].center = centers[i];
buttons[iter].bounds = bounds[i];
buttons[iter].alpha = opacities[i];
i++;
iter = [self next:iter];
}
while (iter != index);
iterations = 0;
buttons[index].enabled = YES;
TitleLabel.text = titles[index];
}
- (NSInteger)back:(NSInteger) i
{
return i == 0 ? 5 : i - 1;
}
- (NSInteger)next:(NSInteger) i
{
return i == 5 ? 0 : i + 1;
}
는 상기 나의 코드가 작동하지만, 일부 조정 또는 여러 아마도이 필요합니다! :
여기 내 코드입니다
1) 첫 번째 문제는 회전 목마가 매우 느리게 왼쪽/오른쪽으로 이동한다는 것입니다. 시간을 변경하지만 여전히 파악하지 못했습니다 ??????
2) 뒤에서 회전 할 때 나는 여전히 회전 장치에서 단추를 볼 수 있습니다. 나는 0으로 알파를 설정하지만 여전히 볼 수 있습니다 ???? 나는 새로운 해요
목적은-C 내 실수에 대한 유감, 오브젝티브 -C는 C++
도움과 조언 바랍니다 매우 다릅니다 ???