Home > ios > Place frame over UIImage not working

Place frame over UIImage not working

March 11Hits:2

I have a UIView that needs to be placed over a UIImage inside of a UIImageView at specific coordinates. The coordinates for the frame are referenced from the top left corner and have a specified width and height refrenced from the original image.

So, to make the frame, I am first getting the CGRect of the image using a category from the following post: UIImage size in UIImageView

I then get a scale factor to shrink the size of the frame by taking the original height, dividing it by the scaled height, and then dividing all of my values by that.

Lastly, I take the image CGRect and add the scaled position values of the frame to get my final CGRect for the view. However, the frame is always up and to the right of the desired location. Can anyone see what I'm doing wrong?

Here's the code (new is just a custom object with the correct frame parameters):

CGRect imageBounds = [self.imageView displayedImageBounds];           float scaleFactor = AppDelegate.usedImage.size.height / imageBounds.size.height;          new.height /= scaleFactor;         new.width /= scaleFactor;         new.positionX /= scaleFactor;         new.positionY /= scaleFactor;          UIView *faceRectView = [[UIView alloc] init];         faceRectView.tag = idx;         faceRectView.backgroundColor = [UIColor whiteColor];        faceRectView.frame = CGRectMake((imageBounds.origin.x + new.positionX), (imageBounds.origin.y + new.positionY), new.width, new.height);           [self.view addSubview:faceRectView]; 

Related Articles

  • Place frame over UIImage not workingMarch 11

    I have a UIView that needs to be placed over a UIImage inside of a UIImageView at specific coordinates. The coordinates for the frame are referenced from the top left corner and have a specified width and height refrenced from the original image. So,

  • how to show video/movie in uiview with uimage frames (frames received over tcp connection are in base64String)January 15

    I am working with Video calling app from scratch. My app is working fine till I capture Video frames at runtime using captureOutput:didOutputSampleBuffer:fromConnection and converted sampleBuffer to frame's UIImage and sent the base64String format of

  • Checkbox image toggle in UITableViewCell

    Checkbox image toggle in UITableViewCellJuly 23

    I need some guidance on creating a UITableViewCell that has an image on the left which can be toggled. The image should be tappable and act as a toggle (checkbox). My parts I'm struggling with are: How do I detect taps on the image and handle those d

  • IOS: create a UIImage or UIImageView with rounded corners

    IOS: create a UIImage or UIImageView with rounded cornersOctober 9

    Is it possible create an UIImage or an UIImageView with rounded corners? Because I want take an UIImage and show it inside an UIImageView, but I don't know how to do it. --------------Solutions------------- Yes, it is possible. Import the QuartzCore

  • Setting up images for frame animation

    Setting up images for frame animationJune 27

    I am learning the basics of iPhone frame animation. I have code that loops through 15 images to do an animation: - (void)viewDidLoad { [super viewDidLoad]; UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(40, 40, 95, 70)]; NSMutableArr

  • IOS (Objective-C) How to indefinitely change the image in a UITableView Cell from an Array of UIImagesMarch 13

    How can I make two images interchangeably animate indefinitely in a UITableViewCell? Update (Solution so far): I was able to look into UIImage Animations and here's my current solution NSArray *imagesArray = [NSArray arrayWithObjects:imageA,imageB,ni

  • UIImage passed to method on another thread crashes CGContextDraw with EXC_BAD_ACCESSJanuary 15

    I am currently working on an app which requires me to do some image processing. So I have the user take an image and all steps of the processing are shown. Thus I create a grey-scale version of the image, pass it to the processing class (by setting o

  • How to set a small image on a uiimage view on a particular position?January 16

    I created an UIView. I need to set a small image on a particular position. I can do it setting the image in a small separate view. But, I plan to do it dynamically on a Large UIView which is full screen. Thanks. --------------Solutions------------- U

  • IBDesignable: render a UIView in storyboard using IBInspectable an UIImage - Objective CJanuary 18

    I'm creating a UIView that allows the user to vote using a classical 5 stars rate system. My code works and everything is fine but I would like to make a preview on the storyboard using IBInspectable variables. I really do not know how to achieve tha

  • Cube transition between UIImages

    Cube transition between UIImagesJanuary 19

    I would like to create a view that when scrolled horizontally transitions between an array of UIImage objects with a cube animation effect. For example: Can someone please point me in the right direction on how I can scroll horizontally through an ar

  • Custom UIImage as UIBarButtonItem showing up pixelated/blurry

    Custom UIImage as UIBarButtonItem showing up pixelated/blurryJanuary 22

    I'm using a custom image as a bar button item. Looks good on iPhone screens, but seems to be pixelated when running on a larger display (iPads). iPad2: iPhone 6S: Here's my code: // Set Custom Image for Bar Button Item let button = UIButton(type: .Cu

  • Rounding UIImage and adding a border

    Rounding UIImage and adding a borderJanuary 25

    so I want to show some pictures as annotations on the map. In order to do that I need to add the image property of the MKAnnotationView. I'm using the regular images but I want them to be rounded and with a border. So I found a way to round UIImage a

  • How to convert only some of the subviews of a UIView to UIImageJanuary 26

    I have been stuck on this since yesterday. I am trying to capture only some of the subviews of a UIView. This main UIView has 4 subviews namely, the header, the caption, the image, and the footer. I am trying to capture the caption and the image only

  • iOS AVFoundation how to convert camera frames per second to create a timelapse using CMTime?January 27

    I have an iPhone camera attachment that captures video at 9FPS and makes it available as individual UIImages. I'm trying to stitch these images together to create a timelapse video of what the camera sees using AVFoundation. I'm not sure how to prope

  • How to change from UILabel to UIImage for segmentedController Buttons?January 28

    I have created a custom segmentedController following this tutorial on youtube : https://www.youtube.com/watch?v=qT1ZEE2CBDQ I have manged to create it and have it functioning correctly. But now I would like to change the UILabel to an image icon. I

  • UIImage built from CMSampleBuffer not retained and causing EXC_BAD_ACCESSJanuary 30

    I am building a UIImage from a CMSampleBuffer. From the main thread, I call a function to access the pixel data in the CMSampleBuffer and convert the YCbCr planes into an ABGR bitmap which I wrap in a UIImage. I call the function from the main thread

  • Animate a UIImage which is drawn with a blend mode to the backgroundFebruary 7

    I have several rounded rect's that i filled and set a blend mode to make it blend to the background image by doing something like this: UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0); UIImage *bgImage = [UIImage imageNamed:@"UE

  • Combine UILabel and UIImage using CGContext

    Combine UILabel and UIImage using CGContextFebruary 8

    I'm having trouble combining a UILabel and UIImage to one single UIImage. I have a UILabel that can be translated, scaled and rotated by the user on top of a UIImage(View). When i try to combine to one UIImage using CGContext, CGContextTranslateCTM a

  • Get video frame in sliders in Objective CFebruary 10

    I am trying to get an image from AVAsset, but I am not able to get it. Can anyone help me? MP4 format is working fine, MOV format isn't. I am getting the following error: Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo=0x

  • How to programmatically insert UIImage into any given textField such as facebook messages or iMessages? February 11

    I'm trying to build a keyboard extension. As buttons we have pictures just like stickers on facebook. So far my buttons assembles pictures and the idea is to print the image into a textField, the user can send in fx Imessages. The func buttonPressed

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.484 s.