Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为UISegmentedControl图像设置动画_Ios_Objective C_Animation_Uisegmentedcontrol - Fatal编程技术网

Ios 为UISegmentedControl图像设置动画

Ios 为UISegmentedControl图像设置动画,ios,objective-c,animation,uisegmentedcontrol,Ios,Objective C,Animation,Uisegmentedcontrol,我正在尝试在UISegmentedControl中设置图像动画。这是我想到的,但它不起作用 如果在最后一行代码中将imageView.layer切换到_segmentedControl.layer,动画本身工作正常 我错过了什么 UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = [_segmentedControl imageForSegmentAtIndex:0];

我正在尝试在UISegmentedControl中设置图像动画。这是我想到的,但它不起作用

如果在最后一行代码中将imageView.layer切换到_segmentedControl.layer,动画本身工作正常

我错过了什么

        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [_segmentedControl imageForSegmentAtIndex:0];
        CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        scale.duration = 0.25;
        scale.repeatCount = 2;
        scale.autoreverses = YES;
        scale.fromValue = [NSNumber numberWithFloat:1.0];
        scale.toValue = [NSNumber numberWithFloat:0.0];
        [imageView.layer addAnimation:scale forKey:@"scale"];

您可以使用集合视图。UISegmentedControl无法设置动画

,仅供将来参考。我想与大家分享我提出的解决方案。您至少可以为分段控件的子视图设置动画,而不是为分段的图像设置动画(这似乎是不可能的)

        UIView *subView = [[_segmentedControl subviews] objectAtIndex:0];
        CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        scale.duration = 0.25;
        scale.repeatCount = 1;
        scale.autoreverses = YES;
        scale.fromValue = [NSNumber numberWithFloat:1.0];
        scale.toValue = [NSNumber numberWithFloat:0.95];
        [subView.layer addAnimation:scale forKey:@"scale"];