开发者

How do I modify my code to allow user to position a UIImage on a UIImageView?

开发者 https://www.devze.com 2023-03-22 18:58 出处:网络
I have the following code where I am hard coding a UImage on a UIImageView. However I have been asked to modify so that the application allows user to select where on the UIImageView, the UIImage need

I have the following code where I am hard coding a UImage on a UIImageView. However I have been asked to modify so that the application allows user to select where on the UIImageView, the UIImage needs to be placed at. I am thinking the user clicks on the screen and the application stores the x,y coordinates where I place the UIImage. I just don't know how to get about doing that.

CGPDFDocumentRef document = CGPDFDocum开发者_开发百科entCreateWithURL((CFURLRef)pdfUrl);

            //lets now convert the fax to an image
            CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
            UIImage *pageImage = [PDFPageConverter convertPDFPageToImage:page withResolution:144];

        UIImage *shieldLogo = [UIImage imageNamed:@"shield_bw.gif"];
        UIGraphicsBeginImageContext(pageImage.size);
        [pageImage drawInRect:CGRectMake(0, 0, pageImage.size.width, pageImage.size.height)];
        [shieldLogo drawInRect:CGRectMake(150, 100, shieldLogo.size.width, shieldLogo.size.height)];
        [theSignature drawAtPoint:CGPointMake(200, 100) withFont:[UIFont fontWithName:@"Arial" size:15.0]];
        [theSignature2 drawAtPoint:CGPointMake(200, 120) withFont:[UIFont fontWithName:@"Arial" size:15.0]];
        UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        [image setImage:resultingImage];


Make your subclass responding to touch events using -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;, in which you will modify the frame property of the image view accordingly.


You can also use UIGestureRecognizers in order to alter the UIImage's position.

This is the tutorial that I used to learn how and does a better job than I can here.

http://www.icodeblog.com/2010/10/14/working-with-uigesturerecognizers/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+icodeblog+%28iCodeBlog%29

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号