UIView position relative to photo taken - ios

I have a UIViewController which consists of several UIView elements. From this view controller a photo is taken using AVCapturePhotoOutput.
Then, from the output, UIImage is built.
Is it possible to know the position of a specific UIView seen on a preview layer (lets say SpecificView) in the result image? For example, I'd like to draw a horizontal line on the image at the position where SpecificView was when taking a photo.
I can get SpecificView.y relative to UIWindow, then multiply it by UIScreen.main.scale to get pixels but it doesn't seem to be solution.
Any ideas?

Related

How does an imageView appears in layers?

example
I'm looking for help developing a UIImageView that appears like the imageviews in photo. It will include several images. I want it to be appears in layers.
I think you're best off making a custom class (UIView) which accepts a few images. Then in that custom class, draw those images in UIImageView. Every time you're drawing that image make sure you're rotating the UIImageView a few degrees using transform. You could do something with a white border, too. This will intensify the 'polaroid photo' effect.

How to create a non-rectangular UIImageView

I'm trying to make a ViewController that presents info from a webpage like this:
However, I'm confused on one thing. How did they get the imageView to display an image that's cut off at the corner, i.e. not rectangular? Do you think they created that player card in Photoshop and used it as the background for the imageView image, or did they create it programmatically?
I wonder because the image is behind the picture of the bear, so I imagine if they created the background in Photoshop, how would they get the image behind the bear head? They can't have just created the card with the player's picture as part of it, then loaded the whole image because if they traded the player, because I'm sure they pull the player info and picture from the web so they can have a card for all players, even if they trade or acquire a new player mid-season, without having to update the app (and add the finished image to images.xcassets).
This can be composed from two CALayers at runtime. Put the picture on the bottom layer; the picture can come from anywhere - the web, the bundle, etc. the image source could be dynamic.
Put another CALayer on top, with the frame rendered with opaque colors, and a transparent cut-out for the picture in the middle:
There are a bunch of ways to do this. A simple and flexible way to do it is to create a CAShapeLayer that's the same size as the image view, with it's origin at 0,0, and add it as the UIImageView's layer's mask.
You'd create a filled UIBezierPath that maps out the part of the image you want to show, and install the bezier path's CGPath into the mask layer's path property.
The result would be that the image view is cropped so that only the part inside the shape is drawn.

How to make a portion of an UIImageView transparent in order to show views in layers below

Here is a photo explanation to better illustrate what I mean:
I have two UIImageViews, with View1 being on the bottom and View2 at the top:
What I would like to do accomplish is to programmatically set an area on View2 that is completely transparent (i.e. has an alpha of 0), so that this will be the end result:
I haven't been able to find a similar problem related to marking a part of a UIImageView transparent in the form of a shape (specifically, a circle), and was wondering how I should tackle this problem?
Thanks!
One road you could go is CoreGraphics:
Create an image context
Set the clipping path you need (or just clear the circle for the "hole" after drawing)
Draw the original image into the context
Make an UIImage from that context
Assign the image to the top UIImageView
https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/HandlingImages/Images.html#//apple_ref/doc/uid/TP40010156-CH13-SW1

Apply a CIFilter to a UIView & all subviews

I have a UIView, that contains a UIImageView for its background. The view contains a number of segments (UIImageViews), which the user can drag and drop images to. I want to add a CIFilter to the whole view, such that any images that are subsequently dropped into the view will have the filter applied instantly. But the filter shouldn't be applied to the main view's background image. I realise that a CIFilter requires an input image, I was thinking of using a transparent input image, then placing the filter on top of all the views so it would only be visible when there is an image behind it.
Is it possible to supply a transparent input image to a CIFilter?
Is this the best way of going about it?
I suppose I'd need to mask the filter to the view containing the segments so that it is not applied to the background image. How would I go about this? Since a mask needs an image to mask to, I guess I'd need to render the segments view to an image and mask to this?
Thanks in advance

How to use a UIView with a CCLayer cocos2d?

I am playing a short video with CCVideoPlayer in cocos2d and at the end of it I am capturing the very last frame of the video and I am showing it on the screen using a UIView because trying to draw it on a CCLayer makes the image show up with slightly different colors. I would imagine that is because the way that things are drawn in cocos2d is different than the way they are drawn on a UIView. So I need some way to keep the image on the screen Using the UIView, and I need to be able to draw sprites etc... on top of this view. So my question is, Is there a way to make a CCLayer transparent so that the UIView containing the image can still be seen and then draw on top of the image using a CCLayer?
(P.S I am using cocos2d v1.1.0-beta2b)

Resources