0812-图片浏览 & Tom猫 (放大缩小)(button图像的transform位移形变 放大)(button图像的transform放大)(button图像的transform旋转)(代码创建按...

---------------

放大缩小

步骤:

1、导入素材 拖button图片控件 设置控件属性为custom    取消自动布局

2、连线方法 

3、同时修改frame或者bounds的宽度和高度

4、加入收尾动画 (这个不常用)

 

- (IBAction)zoom:(UIButton *)button
{
    CGRect bounds = self.image.bounds;
    if (button.tag) {
        //放大
        //取出bounds或frame

        //修改bounds
        bounds.size.width += 20;
        bounds.size.height +=20;
        
    }else{
        //缩小
        bounds.size.width  -=20;
        bounds.size.height -=20;
    }
    [UIView beginAnimations:nil context:nil];
    // 设置动画时长
    [UIView setAnimationDuration:1.0];
    // 设置bouds
    self.image.bounds = bounds;
    
    [UIView commitAnimations];
}

 

---------

button图像的transform位移形变

步骤

1、改变button图片的transform

    self.image.transform = CGAffineTransformTranslate(self.image.transform, 0, -20);  追加的方式改变transform

 2、打印tranform

    NSLog(@"%@",NSStringFromCGAffineTransform(self.image.transform));

-------

button图像的transform放大

    CGFloat scale = (button.tag)?1.2f : 0.8;
    CGAffineTransform transform = CGAffineTransformScale(self.image.transform, scale, scale);
    self.image.transform = transform;

-------

button图像的transform旋转

    //旋转角度
    CGFloat angle = (button.tag)?-M_PI_4:M_PI_4;
     
    self.image.transform = CGAffineTransformRotate(self.image.transform, angle);

------------

代码创建按钮

步骤:

1、根据stroyboard的上下集成各个属性  找到相应的.h类文件对应的属性名称

2、代码创建custom类型button(alloc init创建的是custom类型的,最纯洁的代码创建的)  并交给控制器button属性  (storyboard中是将storyboard中的button连线 就是赋值给控制器button属性 连线是为了后期代码修改)    创建系统自带的button 这里暂时不连线

3、设置button属性

4、添加自定义到控制器视图上 self.view addSubviews上

- (void)viewDidLoad {
    [super viewDidLoad];

    //创建系统自带的button
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    btn.center = CGPointMake(50, 50);
    [self.view addSubview:btn];
    
    
    //代码创建custom button
    UIButton *image = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    //连线交给控制器属性Image
    self.image = image;
    image.backgroundColor = [UIColor redColor];
    
    //设置背景图片
    [image setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal];
    [image setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];
    
    //设置标题文字
    [image setTitle:@"点我啊" forState:UIControlStateNormal];
    [image setTitle:@"我是abc" forState:UIControlStateHighlighted];
    
    //设置文字颜色
    [image setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [image setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    
    //设置标题文字对齐方式
    image.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    [self.view addSubview:image];
    
}

 ---------

系统头文件修改后处理

xcode->preferences->locations->derived data 进入   删除 derived data换成目录里面的所有文件

---------

button点击切换图片界面

 

步骤

1、导入png图片到image.assets (图片抽取放到一个folder中 选择图片->new folder from selection 变成蓝色的文件夹)

2、图片切换代码搭建

- (void)viewDidLoad {
    [super viewDidLoad];

    // number
    _number = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 40)];
    
    _number.text = @"1/5";
    _number.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_number];
    
     // image
    CGFloat imageW = 200;
    CGFloat imageH = 200;
    CGFloat imageX = (self.view.bounds.size.width - imageW) * 0.5;
    CGFloat imageY = CGRectGetMaxY(_number.frame) + 20;
   
    _image = [[UIImageView alloc] initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)];
//    _image.backgroundColor = [UIColor redColor];
    _image.image = [UIImage imageNamed:@"biaoqingdi"];
    [self.view addSubview:_image];
    
    // descriptionLabel
    CGFloat y = CGRectGetMaxY(_image.frame);
    _descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, y, self.view.bounds.size.width, 100)];
    _descriptionLabel.text = @"神马表情";
    _descriptionLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_descriptionLabel];
    
    // 左边按钮
    
    _leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    _leftButton.center = CGPointMake(_image.frame.origin.x * 0.5, _image.center.y);
    [_leftButton setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];
    [_leftButton setBackgroundImage:[UIImage imageNamed:@"left_highlighted"] forState:UIControlStateHighlighted];
    
    [self.view addSubview:_leftButton];
    
    // 右边的按钮
    _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    _rightButton.center = CGPointMake(self.view.bounds.size.width - _image.frame.origin.x * 0.5 , _image.center.y);
    
    [_rightButton setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal];
    [_rightButton setBackgroundImage:[UIImage imageNamed:@"right_highlighted"] forState:UIControlStateHighlighted];
    
    [self.view addSubview:_rightButton];
    
    
    
}

-------

界面图片切换数据处理

1、界面搭建

2、控件懒加载(保证只加载一次)到界面  ,@property数组数据懒加载  数组数据最好用plist

(不用plist前的土办法:数组包字典 数据 

NSDictionary *dict1 = @{@"name":@"biaoqingdi",@"desc":@"表情111111"};

NSDictionary *dict2 = @{@"name":@"wangba",@"desc":@"王八22222222"};

_imageList = @[dict1,dict2,dict3];

)

3、viewDidLoad中设置控件赋值 顺便执行了控件懒加载

//
//  ViewController.m
//  03-图片查看器
//
//  Created by imac on 16/2/21.
//  Copyright (c) 2016年 china. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic,strong) UILabel *number;
@property (nonatomic,strong) UIImageView *image;
@property (nonatomic,strong) UILabel *descriptionLabel;
@property (nonatomic,strong) UIButton *leftButton;
@property (nonatomic,strong) UIButton *rightButton;

@property (nonatomic,assign) int index;
@property (nonatomic,strong) NSArray *imageList;

@end

@implementation ViewController

- (NSArray *)imageList
{
    if (_imageList == nil) {
        // 图片name和description文字
        // 获得plist array数据
        NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageList" ofType:@"plist"];
        _imageList = [NSArray arrayWithContentsOfFile:path];
    }
//    NSLog(@"%@",_imageList);
    return _imageList;
    
}

- (UILabel *)number
{
    if (_number == nil) {
        _number = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 40)];
        
//        _number.text = @"1/5";
        _number.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:_number];
    }
    return _number;
}

- (UIImageView *)image
{
    if (_image == nil) {
        CGFloat imageW = 200;
        CGFloat imageH = 200;
        CGFloat imageX = (self.view.bounds.size.width - imageW) * 0.5;
        CGFloat imageY = CGRectGetMaxY(_number.frame) + 20;
        
        _image = [[UIImageView alloc] initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)];
        //    _image.backgroundColor = [UIColor redColor];
//        _image.image = [UIImage imageNamed:@"biaoqingdi"];
        [self.view addSubview:_image];
    }
    return _image;
}

- (UILabel *)descriptionLabel
{
    if (_descriptionLabel == nil) {
        CGFloat y = CGRectGetMaxY(_image.frame);
        _descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, y, self.view.bounds.size.width, 100)];
//        _descriptionLabel.text = @"神马表情";
        _descriptionLabel.textAlignment = NSTextAlignmentCenter;
        _descriptionLabel.numberOfLines = 0;
        [self.view addSubview:_descriptionLabel];
    }
    return _descriptionLabel;
}

- (UIButton *)leftButton
{
    if (_leftButton == nil) {
        _leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        _leftButton.center = CGPointMake(_image.frame.origin.x * 0.5, _image.center.y);
        [_leftButton setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];
        [_leftButton setBackgroundImage:[UIImage imageNamed:@"left_highlighted"] forState:UIControlStateHighlighted];
        _leftButton.tag = -1;
        [self.view addSubview:_leftButton];
        [_leftButton addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftButton;
}

- (UIButton *)rightButton
{
    if (_rightButton == nil) {
        _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        _rightButton.center = CGPointMake(self.view.bounds.size.width - _image.frame.origin.x * 0.5 , _image.center.y);
        
        [_rightButton setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal];
        [_rightButton setBackgroundImage:[UIImage imageNamed:@"right_highlighted"] forState:UIControlStateHighlighted];
        _rightButton.tag = 1;
        [self.view addSubview:_rightButton];
        // 监听按钮点击事件
        [_rightButton addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightButton;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self imageList];
//显示界面
    
    [self show];
    
}
- (void) next:(UIButton *)button
{
    NSLog(@"%s ---- %d",__func__,self.index);
    self.index += button.tag;
    //重新显示界面
    [self show];
    
}
- (void)show
{
    // number
    self.number.text = [NSString stringWithFormat:@"%d/%d",self.index+1,5];

    // image
    self.image.image = [UIImage imageNamed:self.imageList[self.index][@"name"]];

    // descriptionLabel
    self.descriptionLabel.text = self.imageList[self.index][@"desc"];

    // leftButton
    self.leftButton.enabled = (self.index != 0);

    // rightButton
    self.rightButton.enabled = (self.index != 4);

   
}

@end

 

------

按钮添加监听事件

步骤 添加监听方法next 如果next: 则相当于 next:_rightButton 默认自身是第一个参数

    [_rightButton addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
- (void) next
{
    NSLog(@"%s",__func__);
    self.index++;
    
}

 

------

取出包(mainBubdle)中的plist 

(包中包含真正的应用程序 包含exec文件 资源等)

1、包路径 NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageList" ofType:@"plist"];

2、打印包路径 , finder中找到该包位置

NSLog(@"%@",paht);

直接abc.plist-》show in finder 查看的是该程序自己存放的位置 对应的plist 不是系统中的

 --------

Strong weak变量

(强人牵狗  弱人只能看狗)

默认对象都是强引用的如 Person *p1 = [[Person alloc] init];  弱引用 __weak Person *p1

 

Person对象必须要有强引用指向  否则立即会被回收,不能存在

Person *p = [[Person alloc] init] //强人p牵狗

__weak Person p2 = p;//弱人看狗

 

 ---------

TOM猫ImageView动画和清理数组

步骤:

xcode6.4取消 use Size Classes

viewController下拖入一个View

1、素材导入 button文件夹拖到image.assets中 里面都是png图片(3个勾选 create Folder),animations文件夹中都是 jpg的 拖到supporting files中 (3个勾选 create Group)

2、吃鸟图片连线方法 viewDidLoad方法删除

3、使用UIImageView的属性搜索animation相关

isAnimation则退出 animationImages存放图片数组 startAnimation 

(

ImageNamed方法系统来管理的 在动画中不能用这个 否则内存占用越来越大

NSString *path = [NSBundle mainBundle] pathForResources:@"abc.jpg" ofType:nil];

使用[UIImage imageWithContentsOfFile:path];

image.assets中优先使用imageNamed这里的图片常驻内存,     supporting Files中图片优先使用 imageWithContentsOfFile 这里都是临时使用的图片

)

4、等动画结束后 ,清空UIImageView的动画数组

[self performSelector:@selector(cleanup) withObject:nil afterDelay:self.tom.animationDuration];

 - (void) cleanup

{

self.tom.animationImages = nil;

}

(或者用 [self performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration]; 一个方法即可 )

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tom;

@end

@implementation ViewController

- (IBAction)eat
{
    // 如果正在动画,直接退出
    if ([self.tom isAnimating]) return;
    
    // 动画图片的数组
    NSMutableArray *arrayM = [NSMutableArray array];
    
    // 添加动画播放的图片
    for (int i = 0; i < 25; i++) {
        // 图像名称
        NSString *imageName = [NSString stringWithFormat:@"angry_%02d.jpg", i];
        //        UIImage *image = [UIImage imageNamed:imageName];
        // ContentsOfFile需要全路径
        NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        
        [arrayM addObject:image];
    }
    
    // 设置动画数组
    self.tom.animationImages = arrayM;
    // 重复1次
    self.tom.animationRepeatCount = 1;
    // 动画时长
    self.tom.animationDuration = self.tom.animationImages.count * 0.075;
    
    // 开始动画
    [self.tom startAnimating];
    
    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration];
}



@end

 

其他不需要了解的

方法2(不常用):@property (nonatomic,assign) CGFloat y;

    self.y -=20;
    self.image.transform = CGAffineTransformMakeTranslation(0, self.y);   相对于第一次的transform基础上增加y

旋转后 应当修改bounds center才是正解 用frame有时候会出问题

#pragma mark - 操作1

生成的带下划线 _noLabel不经过getter 和 setter方法

双击image.assets 弹出窗口 方便查看 

_noLable.numberOfLine = 0;显示不够 自动换行

- (void) dealloc{NSLog(@"被释放了");} 判断对象是否被释放

其他项目中的代码直接拖进我的代码中

 

@property (nonatomic,strong) Person *p;

@property (nonatomic,copy) NSString *str;

@property (nonatomic,assign) int age;

拖线用weak

 Button有一个currentTitle属性  因为标题分2种状态

mac拖图片到xcode中  拖到image.assets 3个勾选 create Folder,拖到supportingFiles中 3个勾选 create Group

转载于:https://www.cnblogs.com/zff193/p/5204496.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vue-quill-editor 是基于 Quill.js 封装的一个 Vue 富文本编辑器组件,要实现图片拉伸放大缩小,需要对 Quill.js 进行操作。 首先,需要在 Quill.js 的 toolbar 中添加图片缩放按钮。可以参考 Quill.js 官方提供的 custom toolbar demo,添加一个 &ldquo;zoom&rdquo; 按钮。 ``` &lt;div id=&quot;toolbar&quot;&gt; &lt;button class=&quot;ql-bold&quot;&gt;&lt;/button&gt; &lt;button class=&quot;ql-italic&quot;&gt;&lt;/button&gt; &lt;button class=&quot;ql-underline&quot;&gt;&lt;/button&gt; &lt;button class=&quot;ql-image&quot;&gt;&lt;/button&gt; &lt;button class=&quot;ql-zoom&quot;&gt;&lt;/button&gt; &lt;/div&gt; ``` 然后,在初始化 Quill 实例时,需要监听 &ldquo;selection-change&rdquo; 事件,检测当前选中区域是否包含图片,并动态显示或隐藏 &ldquo;zoom&rdquo; 按钮。 ``` var quill = new Quill(&#39;#editor&#39;, { modules: { toolbar: &#39;#toolbar&#39; }, theme: &#39;snow&#39; }); quill.on(&#39;selection-change&#39;, function(range, oldRange, source) { if (range) { var currentFormat = quill.getFormat(range); if (currentFormat.image) { document.querySelector(&#39;.ql-zoom&#39;).style.display = &#39;inline-block&#39;; } else { document.querySelector(&#39;.ql-zoom&#39;).style.display = &#39;none&#39;; } } }); ``` 接下来,实现 &ldquo;zoom&rdquo; 按钮的具体操作。可以通过监听 &ldquo;click&rdquo; 事件,获取当前选中的图片对象,然后对图片设置样式来实现缩放操作。 ``` var zoomButton = document.querySelector(&#39;.ql-zoom&#39;); zoomButton.addEventListener(&#39;click&#39;, function() { var range = quill.getSelection(); if (range) { var currentFormat = quill.getFormat(range); if (currentFormat.image) { var img = quill.getSelection().getNativeRange().getBoundingClientRect().top; img.style.width = &#39;200px&#39;; img.style.height = &#39;200px&#39;; } } }); ``` 需要注意的是,这里的缩放操作只是简单地改变了图片的宽高值,而没有进行真正的图片缩放。如果需要实现更复杂的缩放效果,可以使用第三方库,比如 jQuery 的 resizable 方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值