昨天看了sina微博,看到cell右下角的图片,就想到思路应该是clip+rotate,今天随手测试,确实如此,果断上code:
UIView *containView=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 80)];
containView.backgroundColor=[UIColorredColor];
containView.layer.cornerRadius=10;
containView.clipsToBounds=YES;
[window addSubview:containView];
UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake((200-80), (80-40), 100, 60);
[btn setBackgroundImage:[UIImageimageNamed:@"touxiang.jpg"] forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
btn.layer.transform=CATransform3DMakeRotation(30.0*M_PI/180.0, 0, 0, 1);
[containView addSubview:btn];
还是很简单的,就两个地方:
1.containView.clipsToBounds=YES;当subviews的size超出superview的范围时,就把超出的那部分剪切掉;另外,在NO的情况下,超出的那部分是不能响应touchUpInside,不知为何...
2.btn.layer.transform=CATransform3DMakeRotation(30.0*M_PI/180.0, 0, 0, 1);这个简单地在Z上变换一下而已,细节参考文档
效果如下: