首页 > 代码库 > iOS,视图相关
iOS,视图相关
1.移除视图的所以子视图
2.自定义视图(UIView)
3.处理悬浮窗口(类似微信视频),等比缩放
移除视图的所以子视图
[[self.viewsubviews]makeObjectsPerformSelector:@selector(removeFromSuperview)];
或者
NSArray *viewsToRemove = [self.view subviews];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}
自定义视图(UIView)
//FaceView.m文件
@implementation FaceView
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
}
return self;
}
//自己实现drawRect方法重绘 ,也可以不实现该方法,自己定义执行界面处理方法执行
-(void) drawRect:(CGRect)rect{ //省略实现。。。
}@end
处理悬浮窗口(类似微信视频),等比缩放
将要加载的view放在主window上或者根视图控制器上,利用transform将视图等比缩放
下面将一个视图在AppDelegate中处理
FloatingView *view=[[FloatingView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
//添加拖动手势,使视图达到悬浮窗的拖动效果
UIPanGestureRecognizer *panGestures=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestures:)];
[view addGestureRecognizer:panGestures];
//单击视图手势
UITapGestureRecognizer *tapGestures=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(narrowView:)];
[view addGestureRecognizer:tapGestures];
[self.window addSubview:view];
//点击等比缩小视图
-(void)narrowView:(UITapGestureRecognizer *)sender{
//等比缩放视图
sender.view.transform=CGAffineTransformScale(sender.view.transform, 0.5, 0.5);
}
//处理视频视图拖动事件
-(void)handlePanGestures:(UIPanGestureRecognizer *)sender{
if(sender.state!=UIGestureRecognizerStateEnded&&sender.state!=UIGestureRecognizerStateFailed) {
//通过使用 locationInView 这个方法,来获取到手势的坐标
CGPoint location=[sender locationInView:sender.view.superview];
sender.view.center=location;
}
}
iOS,视图相关