• IOS UI 第八篇:基本UI



    实现图片的滚动,并且自动停止在每张图片上
     
     
    - (void)viewDidLoad
    {
        [
    super viewDidLoad];

        
    UIScrollView *scrollView = [[UIScrollView allocinitWithFrame:CGRectMake(020320200)];
        
        
    for (int i=1; i<=8; ++i) {
            
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
            
    UIImageView *imageView = [[UIImageView allocinitWithFrame:CGRectMake(320*(i-1), 0320200)];
            imageView.
    image = image;
            [scrollView 
    addSubview:imageView];
        }
        
        scrollView.
    bounces = NO;
        scrollView.
    showsHorizontalScrollIndicator = NO;
        scrollView.
    pagingEnabled = YES;
        scrollView.
    contentSize = CGSizeMake(320*8200);
        [
    self.view addSubview:scrollView];
        
        
        
    // Do any additional setup after loading the view.
    }
     
     
    将图片猩猩假如scrollView 中
     
    - (void)viewDidLoad
    {
        [
    super viewDidLoad];
         
    UIScrollView *scrollView = [[UIScrollView allocinitWithFrame:CGRectMake(1030300400)];
         scrollView.
    backgroundColor = [UIColor orangeColor];
         
         
    UIImage *image = [UIImage imageNamed:@"1.jpg"];
         
    UIImageView *imageView = [[UIImageView allocinitWithImage:image];
         [scrollView 
    addSubview:imageView];
         scrollView.
    contentSize = CGSizeMake(image.size.width, image.size.height);
         [
    self.view addSubview:scrollView];
        
        
    // Do any additional setup after loading the view.
    }
     
    手势:
     
    @interface QFViewController ()<UIGestureRecognizerDelegate]]>
    @property (weaknonatomicIBOutlet UILabel *myLabel;

    @end

    @implementation QFViewController{
        
    CGFloat preScale;
    }

    - (
    void)viewDidLoad
    {
        [
    super viewDidLoad];
    // 手势
        
    /*
        UITapGestureRecognizer;//
    单击
        UIPinchGestureRecognizer;//
    缩放手势
        UIRotationGestureRecognizer;//
    旋转手势
        UISwipeGestureRecognizer;//
    扫动手势(上下左右)
        UIPanGestureRecognizer;//
    滑动手势
         */

        
    UIPinchGestureRecognizer *pinchGR=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(onPinch:)];
        [
    self.myLabel addGestureRecognizer:pinchGR];
        
    //labelimageview默认不接受人机交互,要手动设置
        
    self.myLabel.userInteractionEnabled=YES;
        
    preScale=1;
    }
    -(
    void)onPinch:(UIPinchGestureRecognizer *)pGR{
        
    NSLog(@"%@",pGR);
        
    NSLog(@"%f",pGR.scale);
        
    /*
         UIGestureRecognizerStateBegan,
         UIGestureRecognizerStateChanged,
         UIGestureRecognizerStateEnded,
         */

        
    if (pGR.state==UIGestureRecognizerStateChanged) {
            
    self.myLabel.font=[UIFont systemFontOfSize:17*preScale*pGR.scale];
        }
        
    if (pGR.state==UIGestureRecognizerStateEnded) {
            
    preScale=preScale*pGR.scale;
        }
        
        
    }

    @end
     

    IOS UI 第八篇:基本UI

  • 相关阅读:
    Python
    算法的时间复杂度和空间复杂度-总结
    列表自动滚动
    React 结合ant-mobile 省市区级联
    5G从小就梦想着自己要迎娶:高速率、低时延、大容量三个老婆
    一文读懂GaussDB(for Mongo)的计算存储分离架构
    cpu占用过高排查
    我是如何从零开始自学转行IT并进入世界500强实现薪资翻倍?
    Linux重定向用法详解
    说出来也许你不信,我被 Linux 终端嘲笑了……
  • 原文地址:https://www.cnblogs.com/firstrate/p/3662124.html
Copyright © 2020-2023  润新知