GVKun编程网logo

iphone – 如何重置UIImageView转换属性(ios uiimageview)

5

在本文中,我们将为您详细介绍iphone–如何重置UIImageView转换属性的相关知识,并且为您解答关于iosuiimageview的疑问,此外,我们还会提供一些关于iOSUIImage拉伸:如何

在本文中,我们将为您详细介绍iphone – 如何重置UIImageView转换属性的相关知识,并且为您解答关于ios uiimageview的疑问,此外,我们还会提供一些关于iOS UIImage拉伸:如何在较小的UIImageView中放置较大的UIImage而不降低任何质量且没有任何空格、IOS UITableViewCell 设置 UIImageView 属性 位置、ios – CGAffineTransformIdentity在多次转换后没有重置UIImageView?、ios – UITableViewCell中的UIImageView在动画UIImage被分配两次时没有动画的有用信息。

本文目录一览:

iphone – 如何重置UIImageView转换属性(ios uiimageview)

iphone – 如何重置UIImageView转换属性(ios uiimageview)

在我的项目中,我正在UI ImageView上进行以下活动
1.)旋转它
2.)移动它
3.)缩放它.
我的项目还有一个名为“New”的按钮,它将重置app.my的所有设置问题是如果我旋转图像并单击新按钮,则UIImageVIew的设置不会改变.可以有人有任何想法.谢谢

-(void)rotate:(id)sender {

    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

        lastRotation = 0.0;
        return;
    }

    CGFloat rotation = 0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);

    CGAffineTransform oldTransform = [(UIPinchGestureRecognizer*)sender view].transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(oldTransform,rotation);

    [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform];

    lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}

以上代码我用于轮换.

解决方法

如果imageView是您的UIImageView对象,则重置transform属性是使用,

imageView.transform = CGAffineTransformIdentity;

此外,如果您没有在其他任何地方使用lastRotation,您可以稍微缩短rotate:方法.

-(void)rotate:(UIRotationGestureRecognizer *)gesture {
    UIView * view = gesture.view;
    view.transform = CGAffineTransformRotate(view.transform,gesture.rotation);
    gesture.rotation = 0;
}

iOS UIImage拉伸:如何在较小的UIImageView中放置较大的UIImage而不降低任何质量且没有任何空格

iOS UIImage拉伸:如何在较小的UIImageView中放置较大的UIImage而不降低任何质量且没有任何空格

![在此处输入图像描述] [1]我从UI ImagePickerController获取UIImage并在UIImageView中显示它.实际上UIImagePickerController是全屏的,因此UIImage也是.但由于存在标题栏,UIImageView未全屏显示.

图像越来越紧张..

我该如何解决..

请帮帮我一个人..

提前致谢…..

第一个图像是图像选择器屏幕,第二个图像是我在UIImageView中显示从拾取器捕获的UIImage的位置.

![这是我的UIImagePickerController] [2]

![这是捕获后的图像显示在UIImageview中. ] [3]

注意:屏幕两者都处于风景模式

解决方法

将此用于UIImageView

imageView.contentMode = UIViewContentModeScaleAspectFill;

您将无法获得任何空间并且保留了比例.但是,图像的某些部分将被剪掉.

如果您使用:

imageView.contentMode = UIViewContentModeScaleAspectFit;

将有一些空的空间,但保留了比例.

IOS UITableViewCell 设置 UIImageView 属性 位置

IOS UITableViewCell 设置 UIImageView 属性 位置

一 问题描述

用 UITableView 做菜单栏,需要设置图片和文字,UITableViewCell 设置图片的时候是居左,要实现效果如下:

想要的效果:                                   实际效果

                


二解决方法

2.1 重新创建 UIImageVIew 视图,并添加到 UITableViewCell 中

//1.创建UIImage
UIImage *image = [UIImage imageNamed:@"power-standby"];    

//2.创建UIImageView
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];

//3.设置imgView 位置
imgView.frame = CGRectMake((cell.frame.size.width-120),cell.frame.size.height*0.2,image.size.width , image.size.height);

//4.设置UIImageView 背景色
imgView.backgroundColor = [UIColor whiteColor];

//5.添加奥UITableView Cell 中
[cell addSubview:imgView];

效果图看图 1


2.2 设置辅助视图

 注意:设置辅助视图,图片是居右的(最右边)

//1.创建 UIImageView
UImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"power-standby"]];
cell.accessoryView = imageView;


图:



2.3 自定义 UITableViewCell , 重写 layoutSubviews 方法

- (void) layoutSubviews
{   
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(X,Y,width ,height);
}



ios – CGAffineTransformIdentity在多次转换后没有重置UIImageView?

ios – CGAffineTransformIdentity在多次转换后没有重置UIImageView?

我在顶部创建了一个带有分段控件的简单应用程序.当我单击控件的两个部分之一时,UI ImageView开始旋转.我有一个重置按钮,将其转换为CGAffineTransformIdentity.

通过来回切换段来第二次调用执行视图旋转动画的方法时会发生此问题.点击重置只会删除最新的动画.我必须第二次切换片段以完全重置动画停止.

当我选择旋转UIImageView的段时调用以下代码,当我在段之间单击时显然第二次调用.

// Begin the animation block and set its name
[UIView beginAnimations:@"Rotate Animation" context:nil];

// Set the duration of the animation in seconds (floating point value)
[UIView setAnimationDuration:0.5];

// Set the number of times the animation will repeat (NSIntegerMax setting would repeat indefinately) (floating point value)
[UIView setAnimationRepeatCount:NSIntegerMax];

// Set the animation to auto-reverse (complete the animation in one direction and then do it backwards)
[UIView setAnimationRepeatAutoreverses:YES];

// Animation curve dictates the speed over time of an animation (UIViewAnimationCurveEaseIn,UIViewAnimationCurveEaSEOut,UIViewAnimationCurveEaseInOut,UIViewAnimationCurveLinear)
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

// Changes the imageViews transform property to rotate the view using CGAffineTransformRotate
// CGAffineTransformRotate(transformToStartFrom,angletoRotateInradians)
// Starting transform property can be set to CGAffineTransformIdentity to start from views original transform state
// This can also be done using CGAffineTransformMakeRotation(angleInradians) to start from the IdentityTransform without implicitly stating so
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform,degreesToradians(90));

[UIView commitAnimations];

重置按钮调用此代码 –

self.imageView.transform = CGAffineTransformIdentity;

解决方法

试试这个
[UIView animateWithDuration:0.2 animations:^() {

    self.imageView.transform = CGAffineTransformIdentity;



}];

ios – UITableViewCell中的UIImageView在动画UIImage被分配两次时没有动画

ios – UITableViewCell中的UIImageView在动画UIImage被分配两次时没有动画

我试图在UITableViewCell的imageView中显示一个动画UI Image.动画图像在第一次分配后显示,但不是每次进一步尝试.

这是TableViewController的代码:

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic,strong) UIImage *animatedImage;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.animatedImage = [UIImage animatedImageNamed:@"syncing" duration:1.0];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static BOOL second = NO;

    static Nsstring *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (second) {

        cell.imageView.image = nil;
        NSLog(@"Removed image");
    }
    else {

        cell.imageView.image = self.animatedImage;
        NSLog(@"Added image");

        if (![cell.imageView isAnimating]) {

            [cell.imageView startAnimating];
            NSLog(@"Started animation for UIImageView: %@",cell.imageView);
        }
    }

    second = !second;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

@end

当我点击两次单元格时,这是输出:

Added image
Started animation for UIImageView: <UIImageView: 0x7197540; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; animations = { UIImageAnimation=<CAKeyframeAnimation: 0x715bc80>; }; layer = <CALayer: 0x71975a0>> - (null)
Removed image
Added image
Started animation for UIImageView: <UIImageView: 0x7197540; frame = (6 6; 30 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x71975a0>> - (null)

解决方法

我强烈建议您不要对cellForRowAtIndexPath中的图像进行任何动画处理,因为如果您有更多图像,则在快速滚动时会出现不需要的效果(单元格图像将因细胞可用性而切换).

我在其中一个项目中做了什么,我为UITableViewDelegate实现了 – scrollViewDidScroll:方法(符合uiscrollviewdelegate),并且我调用了一个方法,它只在可见单元格上为图像设置动画(tableView.visibleCells).

另一方面,我不明白你为什么使用静态BOOL second = NO;你可以简单地检查cell.imageView.image ==是否为零.

还要检查你的动画代码,可能是某些东西在那里没有正常工作(请记住,重复使用单元格).

关于iphone – 如何重置UIImageView转换属性ios uiimageview的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于iOS UIImage拉伸:如何在较小的UIImageView中放置较大的UIImage而不降低任何质量且没有任何空格、IOS UITableViewCell 设置 UIImageView 属性 位置、ios – CGAffineTransformIdentity在多次转换后没有重置UIImageView?、ios – UITableViewCell中的UIImageView在动画UIImage被分配两次时没有动画等相关知识的信息别忘了在本站进行查找喔。

本文标签: