我正在为项目制作一个小动画类型的应用程序。我有一个空间可以在imageView上绘制图像。然后,当你点击新页面按钮时,我需要该图像视图中的图像移动到另一个时间轴上的图像视图。希望你了解我的问题,如果不让我知道你需要什么其他信息。设置一个UIimage视图等于另一个UIimage视图
0
A
回答
1
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
声明2周的UIImageViews,先用图像和第二无任何图像,即,空的UIImageView,但具有原点和大小。
然后,当u想动画,请执行下列操作,
[UIView animateWithDuration:3.0
animations:^{
CGRect sframe = mSecondImgView.frame;
mFirstImgView.frame = sframe;
}
completion:^(BOOL finished){
}];
相关问题
- 1. 让视图在另一个视图中控制UIImage
- 2. Android ConstraintLayout - 将一个视图置于另一个视图上
- 3. 设置的UIImage从视图控制器
- 4. 我如何绘制一个图像到另一个UIImage来创建一个UIImage
- 5. 检查视图等于另一个
- 6. 设置视图的高度等于另一个视图的宽度
- 7. 如何在另一个interFace Builder中显示UIImage视图?
- 8. 将UIImage传递给另一个视图控制器
- 9. 从另一个视图控制器创建UIImage
- 10. 另一个视图的设置视图没有正确设置
- 11. UIImage/tapgesturerecognizer /新视图
- 12. 全屏UIImage视图
- 13. 在UIImage上绘制另一个图像
- 14. UIImage替换另一个UIImage不光滑
- 15. ios UIImage透露另一个UIImage动画
- 16. 只在另一个UIImage内移动UIImage
- 17. 在另一个UIImage顶部添加UIImage
- 18. 从一个视图设置图像到另一个xcode 4.4
- 19. 从一个视图控制器传递一个UIImage到一个UITableViewCell
- 20. 将视图从一个视图移动到另一个视图
- 21. 如何将视图置于React Native的另一个视图中?
- 22. UIImage的另一UIImage的
- 23. UIIMage视图旋转低于90度
- 24. 用子视图修改UIImage
- 25. 如何删除UIImage视图?
- 26. UIImage视图编码为base64
- 27. 在两个视图控制器之间更改UIImage视图
- 28. 将一个视图textfied值设置为另一个视图标签
- 29. 动画调用后UIImage视图重置
- 30. 如何只为一个视图设置UINavigationController图像,然后为其余视图设置另一个图像?
所以无论是imageviews都在同样的看法,对不对? – Ilanchezhian