UI基础整理-5

target_action

重写addtarget: action:方法

让_target来执行_action[button addTarget:self action:@selector(test:)];

imageView

//ios 默认支持的图片格式是 png, 因为在较小尺寸下 ,png 的体积更小 , 方便存储 .
   // 苹果官方建议 , APP 当中 , 图片大小应该不大于 1024*1024, 以免加重 APP 运行负荷 .

// 创建图片对象
   
//根据图片名字直接获取图片对象
//    UIImage *image = [UIImage imageNamed:@"b.jpg"];
   
//根据图片路径来获取图片对象
    UIImage *image =[UIImageimageWithContentsOfFile:@"/Users/lanou3g/Desktop/cc.png"];

    //创建图片视图
   
//    // 公司中一般使用这种
//    // 直接使用图片来创建图片视图 , 可以保留原尺寸比例 ( 视图大小和图片大小一致 )
//    UIImageView *imgView = [[UIImageView alloc]initWithImage:image];
//    [self.view addSubview:imgView];

  // 经常使用的方法
   
UIImageView *imgView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,290,290)];
    imgView.
center=self.view.center;

   
//设置图片
    imgView.
image= image;
   
//调整显示内容为原比例(不拉伸)    UIViewContentModeScaleAspectFit:正常显示
//    imgView.contentMode = UIViewContentModeScaleAspectFit;
   
//添加视图
   
//切圆角
    imgView.
layer.cornerRadius=145;
    imgView.
layer.masksToBounds=YES;
   
   
//图片视图的用户交互是默认关闭的
   
//NSLog(@"%d",imgView.userInteractionEnabled);
   
   
   
//开启视图的用户交互
    imgView.
userInteractionEnabled=YES;//用户交互默认是关闭的
    [self.viewaddSubview:imgView];


方式一:根据图片名字直接获取图片
    UIImage *image = [UIImage imageNamed:@“1.png”];

 方式二:根据图片路径来获取图片

   UIImage *image = [UIImage imageWithContentsOfFile:@"/Users/lanou3g/Desktop/n.jpg"];

手势

从名字上我们就能知道, Tap(点击)、Pinch(捏合)、Rotation(旋转)、Swipe(滑动,快速移动,是用于监测滑动的方向的)、Pan (拖移,慢速移动,是用于监测偏移的量的)以及 LongPress(长按)。

轻拍手势UITapGeatureRecognizer

长按手势UILonngPressGestureRecongnizer

轻扫手势UISwipeGestureRecognizer

旋转手势UIRorationGestureRecognizer

捏合手势UIPinchGestureRecognizer

平移手势UIPanGesturoRecognizer

屏幕边缘轻扫手势UIScreecEdgePanGestureRecognizer

//    // 轻拍手势
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
//    // 触发轻拍收手势需要的点击次数
//    tap.numberOfTapsRequired = 1;
//    // 触发轻拍手势需要的手指个数 (在模拟器中 按住 option 在点鼠标能出来两个手指 )
//    tap.numberOfTouchesRequired = 2;
//   
//   
//    //添加手势(注意:不是addSubview)
//    [imgView addGestureRecognizer:tap];
   
   
   
   
//    // 长按手势
//    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
//    [imgView addGestureRecognizer:longPress];
//    // 最短按压时间 ( )
//    longPress.minimumPressDuration = 3600;

   
   
//    // 轻扫手势
//    UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipAction:)];
//    // 轻扫手势默认设置的方向为向右滑
//    swip.direction = UISwipeGestureRecognizerDirectionLeft;// 修改为往左滑
//    [imgView addGestureRecognizer:swip];

//    // 平移手势
//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
//    [imgView addGestureRecognizer:pan];

//    // 旋转手势
//    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
//    [imgView addGestureRecognizer:rotation];

   
//    // 缩放手势
//    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
//    [imgView addGestureRecognizer:pinch];

   
//屏幕边缘轻扫手势
   
UIScreenEdgePanGestureRecognizer *screenEdge =[[UIScreenEdgePanGestureRecognizeralloc]initWithTarget:selfaction:@selector(screenEdge:)];
    screenEdge.
edges=UIRectEdgeLeft;
    [
self.viewaddGestureRecognizer:screenEdge];
 
   self.view.backgroundColor= [UIColormagentaColor];

以下是关于屏幕的操作:
#pragma mark ---------- 屏幕边缘轻扫手势 --------
-( void )screenEdge:( UIScreenEdgePanGestureRecognizer *)screenEdgePan{
    //触摸屏幕左侧会变色
   
self.view.backgroundColor= [UIColorcolorWithRed:arc4random()%256/255.0green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
}



#pragma mark ----------缩放手势--------
-(void)pinchAction:(UIPinchGestureRecognizer*)pinch{
   
//    // 六个参数 ( 会回到原点 )
//    pinch.view.transform = CGAffineTransformMake(pinch.scale, 0, 0, pinch.scale, 0, 0);
   
//    // 三个参数 ( 不会回到原点 )
//    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
//    pinch.scale = 1;//如果这边不加的话,会缩放的很快,pinch.scale<0是只会缩小,pinch.scale>0是只会放大


   
//两个参数(会回到原点)
     //    pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
}



#pragma mark ---------- 旋转手势 --------
-( void )rotationAction:( UIRotationGestureRecognizer *)rotation{
   
//    // 六个参数
//    rotation.view.transform = CGAffineTransformMake(cos(rotation.rotation), sin(rotation.rotation), -sin(rotation.rotation), cos(rotation.rotation), 0, 0);
   
//    // 两个参数
//    rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
//    rotation.rotation = 0;//如果不加这句话,会转的特别快


   
//一个参数
    //rotation.view.transform = CGAffineTransformMakeRotation(rotation.rotation);   
}


#pragma mark ---------- 平移手势 --------
-( void )panAction:( UIPanGestureRecognizer *)pan{
   
   
//获取手势操作的点
   
CGPoint point= [pan translationInView:pan.view];

//    // 六个参数 ( 会跳回原点 )
//    pan.view.transform = CGAffineTransformMake(1, 0, 0, 1, point.x, point.y);

//    //三个参数
//    //pan.view.transform(会记住变换的位置)
//    pan.view.transform= CGAffineTransformTranslate(pan.view.transform, point.x, point.y);
//    //矫正位置
//    [pan setTranslation:CGPointZero inView:pan.view];

   
    //两个参数(还是会跳回原点)
    //pan.view.transform = CGAffineTransformMakeTranslation(point.x, point.y);
//    NSLog(@"%@",pan.view);
}



#pragma mark ---------- 轻扫手势 --------
-( void )swipAction:( UISwipeGestureRecognizer *)swip{
   
   
NSLog(@"...");
}



#pragma mark ----------长按手势--------
-(void)longPressAction:(UILongPressGestureRecognizer*)longPress{
   
   
NSLog(@"长有本事别放开...");
}


#pragma mark ----------轻拍手势--------
-(void)tapAction:(UITapGestureRecognizer*)tap{
   
   
NSLog(@"拍一拍");
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值