How do I make a textview auto aline to textview? - xcode

How can I have a textview auto-align to an image?
What I mean is, when I change an image from a square to a triangle, how do I make the textview fit inside that triangle automatically?
Check out my "Quick Notes!!" app on the app store for reference. I am using Xcode 4.3.

Chances are you're going to have to do a bit of work to do what you want. I'm guessing you have a background image that changes from a square to a triangle and you want the textbox to remain inside of the shape. Since the imageview hosting the picture is still a rectangular shape the imageview dimensions don't actually change so you'd have to calculate or know the size of your triangle and scale the text box programatically based on a flag of whether or not you are displaying the triangle.
EDIT: Actually this is much simpler than i thought initially. Just position the textbox where you want it with what size in the .xib file and record the position and size. Then you simply check when you are displaying your triangle image and change the position and size of your textbox to what you had previously recorded.

Related

How to crop a photo in a storyboard (Xcode)

I have an image that is part of a vertical stack view (which includes a label and button), and there is a lot of blank space around the image. I was wondering if there was a way to get rid of this empty space so that the label and button are much closer to the actual image. Thank you!
You need to set an Aspect Ratio constraint. Like so:
Set the aspect ratio to 1:1 to get a square. This will prevent your circle image view from expanding to a rectangle.

Is there a way to make the view called when UIImagePickerController.allowsEditing = true have a circle instead of square?

I'm trying to implement a way to allow a user to quickly edit which portion of their selected photo to be an icon. However the default state is simply a square but my icons are circles. I know I can simply make a circle from the square image they select but from a UX standpoint that's not ideal. I would prefer them to simply select an image with knowledge of it being a circle in mind.
As far as I know, there is no way to easily do this. I would suggest keeping it as a square and simply displaying the image in a round imageView.
There should be no significant difference between saving the image as a circle and displaying it as a circle.
Hope this helps.

Flex Mobile GetPixel function of a resized image gets pixel as if the image had its original size

I have an image of 780x585. I am resizing this image to 1246.93x935.19 with scaleMode=ScaleMode.LETTERBOX.
When the user clicks on a graphic and drags it into the picture, I am supposed to get the pixel position where the graphic was dropped.
I do that by listening to the mouse up event and by calling getPixel with the (x,y) coordinates coming from the event when the mouse click is released.
Strange thing is that I get the value of the pixel but not the real one. Instead, I get the value corresponding to the image with it's normal size without being resized.
Does anyone have a clue why this is happening?
Thanks,
Dave
When applying some visual changes to a component (like moving, rotating or stretching as in here), Flex will be applying a transormation matrix to modify only the visual appearance of the object.
Let's say you're moving an image by doing image.width *= 2; the actual image width will be modified. If you do image.matrix.scale(2, 1); (this is pseudo-code), the visual appearance will be modified so you can see the resizing but the the actual width will remain the same.
I think applying a Letterbox resizing is using matrix transformation, so even if your image appears larger, its position and size are still the same. That's why you get the same position as before.
To resolve your problem, you simply have to multiply the coordinates you get (with event.localX or anything else) by the image current scaling and that should be it.
If you already know the final size, you simply have to do something like: newLocalX = event.localX * (resizedImage.width / originalImage.width);
Here some info if you want to know how Matrixes work.

How to control irregular Image button click area in cocos2dx

I want to use multiple irregular picture makes up a map, each picture is a button.Transparent part of the images will overwrite each other, how should I do to make their control areas does not overlap.
I use a lot of pictures makes up a large map.
And each piece of the map is irregular, but their control area is a rectangle. Because they all have transparent pixels.
I just want to make the hit area and their shape becomes the same.Some encountered a similar problem?
I have implemented one for the cocos2d-x v3.x:
https://github.com/yszheda/cocos2d-x-irregular-button
It works OK on cocos2d-x v3.2. Maybe you can have a try XD

About cutting of / cropping a uiview

so i have a uiview that is initialized with a frame that has the height and width that is present for the user, i want the user to be able to draw inside this frame but when the user presses a button, i want the view to cut off that extra wasted space so that the frame is only as big as what the user was drawing. I tried to do something like this
CGRect boundbox = CGPathGetBoundingBox([myPath CGPath]);
boundbox.origin.x = self.frame.origin.x;
boundbox.origin.y = self.frame.origin.y;
self.frame = boundbox;
However, this does not remove that extra wasted space, it only resizes the view, so that the drawn content looks smaller than previously. What i would like to do instead is to remove
that "whitespace", i was thinking if it could be possible to scale up the content of the uiview, but im not sure.
To clarify what i mean:
The red border is the area / frame that the user can draw on, the text in the middle is a drawing, when the user presses a button, i want the frame to only encircle the drawing like in figure 2.
Now lets say i have the following scenario, i have drawn a circle on the middle of the screen.
When i then press the button, the scale remains the same but the circle is still in the same position but we have now changed the draw area, so the circle / drawing will look like its cut off like in figure 4.
What i want to do is to move the drawing / bezier path so that it is positioned in the middle of the frame. So that the red area encircles the blue circle.
[EDIT]
Given your drawings. A UIView will not re-position items in it when you change it's frame property (or it's CGRect). In this case you will need to track the items drawn YOURSELF, and then when the button is pressed perform the object translations yourself.
What that means is you will have to find the object that is left most, the object that is topmost, then move all objects left by that amount, and up by that amount so that all objects are (as a grouping) top-left aligned within the view's frame. After this you will need to self recognize which object is the right most touching and which object is the bottom most touching.
NOW, since you have already moved the items left-top, the right most point will define your frame width, and the bottom most point will define your frame height.
IF YOU SO DESIRE, you should be able to zoom in using the properties below after you have done this.
[First Answer]
If I understand your question correctly, you may want to still perform your box frame manipulation, but if you wish to scale you may want to look into the
contentScaleFactor or
contentStretch
properties.
contentScaleFactor should scale both dimensions based upon a singular floating point value (i.e. xWidth * scaleFactor, yHeight * scale factor).
contentStretch is a CGRect which means that it should scale each dimension (axis) separately.

Resources