UIView 旋转研究

效果如下:



具体代码:

把旋转控制器定义为常量,防止被ARC和谐掉

@interface ViewController ()
{
    CABasicAnimation *_rotationAnimation;
}
@end

具体方法

-(void)buildUI
{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    label.center = self.view.center;
    label.text = @"iOS";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:25];
    label.layer.borderWidth = 1.0f;
    label.textColor = [UIColor blackColor];
    [self.view addSubview:label];
    
    _rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    _rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    _rotationAnimation.duration = 10;
    _rotationAnimation.cumulative = YES;
    _rotationAnimation.repeatCount = HUGE_VAL;
    _rotationAnimation.removedOnCompletion = false;
    [label.layer addAnimation:_rotationAnimation forKey:@"rotationAnimation"];
}



参考资料

Quartz2D 图像处理


在iOS中让图片旋转时抗锯齿

太极旋转动画


模仿网易彩票的幸运大转盘


大转盘抽奖

简单的旋转动画

星座大师转盘特效




好的,我理解了你的要求。你可以通过以下Objective-C代码实现该功能: 首先,在你的UIViewController中添加以下属性: ``` @property (nonatomic, assign) BOOL isFullScreen; @property (nonatomic, strong) UITapGestureRecognizer *tapGesture; ``` 然后,在你的UIViewController的viewDidLoad方法中添加如下代码: ``` self.isFullScreen = NO; self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; [self.view addGestureRecognizer:self.tapGesture]; ``` 接下来,实现handleTapGesture方法: ``` - (void)handleTapGesture:(UITapGestureRecognizer *)tapGesture { if (self.isFullScreen) { [UIView animateWithDuration:0.3 animations:^{ self.view.transform = CGAffineTransformIdentity; self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); }]; self.isFullScreen = NO; } else { [UIView animateWithDuration:0.3 animations:^{ self.view.transform = CGAffineTransformMakeRotation(M_PI_2); self.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width); }]; self.isFullScreen = YES; } } ``` 这里我们使用UIView的transform属性来实现旋转,使用CGAffineTransformMakeRotation方法来创建旋转变换矩阵。同时,我们还改变了UIView的frame属性来使其全屏显示。 当用户点击UIView时,我们会先判断当前UIView是否已经全屏显示,如果已经全屏显示,则执行恢复原样的动画;否则,执行全屏显示的动画。 希望这个代码能够对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值