我正在爲項目製作一個小動畫類型的應用程序。我有一個空間可以在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