Установка представления UIimage равным другому представлению UIimage - PullRequest
0 голосов
/ 12 июля 2011

Я делаю небольшое анимационное приложение для проекта. У меня есть место для рисования изображений в imageView. Затем, когда вы нажимаете кнопку новой страницы, мне нужно, чтобы изображение в этом виде изображения переместилось в другое изображение, которое есть на временной шкале. Надеюсь, вы понимаете мою проблему, если не сообщите мне, какая еще информация вам нужна.

Ответы [ 2 ]

1 голос
/ 12 июля 2011

hai Отметьте этот код. Это позволит вам нарисовать любое изображение, а затем вы сможете получить к нему доступ, используя метод getimage в формате nsdata.и затем вы можете преобразовать его в изображение из nsdata

.h File
//
//  SignatureCaptureImageView.h
//  TEST_DRAW_APP
//

 1. List item

//  Created by Talat Masud on 8/23/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface SignatureCaptureImageView : UIImageView {

    CGPoint lastPoint;

    BOOL mouseSwiped;   
    int mouseMoved;
}
-(NSData *)getImage;

@end


Implementation File


#import "SignatureCaptureImageView.h"


@implementation SignatureCaptureImageView


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Initialization code
        self.userInteractionEnabled = YES;
        mouseMoved = 0;
    }
    return self;
}

- (id)initWithImage:(UIImage*)image {
    if ((self = [super initWithImage:image])) {
        // Initialization code
        self.userInteractionEnabled = YES;
        mouseMoved = 0;
    }
    return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    mouseSwiped = NO;
    UITouch *touch = [touches anyObject];

    if ([touch tapCount] == 2) 
    {
        //self.image = nil;
        return;
    }

    lastPoint = [touch locationInView:self];
    lastPoint.y -= 5;

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    mouseSwiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self];
    currentPoint.y -= 5;


    UIGraphicsBeginImageContext(self.frame.size);
    [self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    self.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

    mouseMoved++;

    if (mouseMoved == 10) {
        mouseMoved = 0;
    }

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    if ([touch tapCount] == 2) {
        //self.image = nil;
        return;
    }


    if(!mouseSwiped) {
        UIGraphicsBeginImageContext(self.frame.size);
        [self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        CGContextFlush(UIGraphicsGetCurrentContext());
        self.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
}

-(NSData *)getImage{
    return  UIImagePNGRepresentation(self.image);
}

- (void)dealloc {
    [super dealloc];
}


@end
0 голосов
/ 12 июля 2011

объявляет 2 UIImageViews, первый с изображением, а второй без изображения, т. Е. Пустой UIImageView, но имеющий происхождение и размер.

Затем, когда вы хотите анимировать, сделайте следующее,

[UIView animateWithDuration:3.0 
                 animations:^{
                     CGRect sframe = mSecondImgView.frame;
                     mFirstImgView.frame = sframe;
                 }
                 completion:^(BOOL finished){

                 }];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...