https://github.com/romaonthego/RESideMenu This is link of RESideMenu.
I am new to ios and i am working on new project in which i have made this kind of side menu bar. But one things which i want is that the window which is going back must get tilt on one side.
Actually I want one side to get decrease in size like flipkart app in ios. So can you please tell me if there is some way to fix this by doing any coding.
You need to apply a CATransform3D to the UIView's layer property transform. An affine transform is a transform in which all sides of the UIView remain parallel. You will need to apply a non affine transform because the top and bottom of your view will not be parallel during the flip effect. You will need to use the underlying UIView's CALayer transform property to apply the CATransform3D. You can access this property through the layer property on your view object. FYI, books have been written about Core Animation, so it is not a light topic especially for a beginner, but as you can see from the code below it is quite simple to apply a 3D rotation to your view.
//Transform
CATransform3D transform = CATransform3DIdentity;
//Modify the perspective transform
transform.m34 = - 1.0 / 500.0;
//Rotate
transform = CATransform3DRotate(transform, M_PI_4, 0, 1, 0);
//Apply transform to the layer
self.layerView.layer.transform = transform;
Related
Here is the view I got, I got a layer view, detect user touch, and a image view, which showing the image. The layer view is cover on top of the image view. The image view's image is aspect fit. So, it won't lost the ratio. If in my layer view touch on 100, 240, it is a layer view coordinate, but not the image's coordinate. I would like to know how to convert the layer view's coordinate to a image's coordinate. In this example, the image size may be 180*180, so, the coordinate in layer view in the image is 60, 90.
Thanks.
If I'm understanding this question correctly, you want to take a point, which is currently in relation to the layer's coordinate system, and convert it to the image view's coordinate system?
In that case, there are a couple of ways to do this.
Easiest is to use convertPoint:fromView: or convertPoint:toView:
CGPoint imageViewTouchPoint = [layerView convertPoint:touchPoint fromView:imageView];
CGPoint imageViewTouchPoint = [imageView convertPoint:touchPoint toView:layerView];
Either one should work.
EDIT - I realize now that this is only if the UIImageView has the same frame as the UIImage, which you said it might not, due to the UIViewContentModeScaleAspectFit property.
In this case, unless I'm mistaken, the image frame is calculated inside the UIImageView drawRect: method and isn't a property that gets set. This means you'll have to calculate this on your own.
Definitely get the imageViewTouchPoint from one of the methods above (just in case you want to use the same logic on a UIImageView which isn't the full screen size).
You will then need to calculate the scaled image frame. There are a couple of ways to do this. Some people go brute force and manually calculate based on which side of the image is longer, then determining which side should be scaled. Then they calculate the origin by by centering the image and subtracting the image and image view's sides and dividing by two.
I like to write as little code as possible if it's unnecessary, even if it means importing a framework. If you import AVFoundation you get a method AVMakeRectWithAspectRatioInsideRect which you can use to actually calculate the scaled rectangle in one line of code.
CGRect imageRect = AVMakeRectWithAspectRatioInsideRect(image.size, imageView.frame);
Whichever method you use, you will then simply translate your touched point with the scaled image origin:
CGPoint imageTouchPoint = CGPointMake(imageViewTouchPoint.x - imageRect.origin.x, imageViewTouchPoint.y - imageRect.origin.y);
You have to do the math yourself. Calculate the aspect ratio of your image and compare with the aspect ratio of the image view's bounds.
Look at this question: How to Get Image position in ImageView
After searching more, got a hack:
CGSize imageInViewSize = [photo resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:imageView.size interpolationQuality:kCGInterpolationNone].size;
CGRect overlayRect = CGRectMake((imageView.frame.size.width - imageInViewSize.width) / 2,
(imageView.frame.size.height - imageInViewSize.height) / 2,
imageInViewSize.width,
imageInViewSize.height);
NSLog(#"Frame of Image inside UIImageView: Left:%f Top:%f Width:%f Height:%f \n", overlayRect.origin.x, overlayRect.origin.y, overlayRect.size.width, overlayRect.size.height);
I've developed a few simple iOS apps, and I'm looking to develop a simple maze game. What I'm looking to do is really basic, so I'm looking for some guidance on which way to go.
Here is basically what I'm trying to do: simple escape-the-maze game where I read in a 2 dimensional array and that makes my maze.
I want the perspective to be standing in the middle of each square, and when you flick or hit a button, it will advance one square, and you can turn left or right. I'd like to be able to apply textures to the ways based on the numbers in the array, and I'd really like to see the movement of the wall moving towards me then stop.
The walls will always be the same height, and the maze will be simple square blocks, although I do want it to be able to hand rooms that might be more than 2x2 , like maybe 4x4, and be able to handle rendering that.
I'm not sure if trying to do something in OpenGL would be overkill since my requirements are really basic. Like I mentioned, it won't be a free move; it will be advance one square each time you hit a button and turn left or right.
I have read something about ray casting for this sort of thing but am not sure how I would accomplish this in iOS. Also I'd like to have the maze not take up the whole screen, maybe 2/3, while the rest is standard iOS controls like buttons and labels, and a background behind it.
What books or articles should I read to help me? I'd prefer not to use a 3rd party engine since this seems really basic.
You can do this using Core Animation, which is much easier than OpenGL. If you import QuartzCore into your project, you can position any view in 3D as follows:
//set the view's 2D position so that the vanishing point is the middle
//of the screen - use the same centre for every view
view.center = CGPointMake(window.bounds.size.width / 2.0f, window.bounds.size.height / 2.0f);
//create a 3d transform
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0f/500.0f; // this sets the 3D perspective
//you can transform the view in 3D relative to the camera
//this rotates the view by 45 degrees about the Y axis
//but you can also scale, translate, etc using equivalent functions
transform = CATransform3DRotate(transform, M_PI_4, 0.0f, 1.0f, 0.0f)
//transform the view in 3D
view.layer.transform = transform;
So if you create your walls as UIImageViews, you can arrange them into a room by transforming each one individually using the logic above.
I realize that by default a UIView is parallel to the X-Y plane, the Z-axis coming straight at you.
How do I rotate this UIView so that it is parallel to X-Z plane? I think I have to use CATransform3D but am not sure what angle I should give it? M_PI_2 or -M_PI_2 ?
Anybody has any idea? Thanks for help...
EDIT: I know that by doing this, the UIView will not be visible to the user, but I want to set a particular UIView this way & then do some rotation animation on it. So this is what I want..
WHat you probably want to do is to apply a transformation to the view's backing layer. The transform property on UIView is an affine transformation, not allowing any 3D manipulation. But accessing view.layer.transform you have a full 4x4 matrix for your transformation needs, allowing nice funky 3d stuff.
Add QuartzCore.framework to your target.
Import <QuartzCore/QuartzCore.h> to get access to the CALayer API.
Code away.
For example:
// Rotate 1/4 by the Y-axis.
myView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0.0f, 1.0f, 0.0f);
I am trying to create a CATransition to a UIView.
I want to move the UIView to the right, and at the same time (and always on the same point), rotate it.
It is better explained by the image.
I am able to move it with a CATransition, and also to rotate it with a CABasicAnimation, but I don't know how to do those together.
Thanks.
-(void)scaleAndRotate:(UIImageView*)myView andAngle:(float)angle {
CGAffineTransform scaleTrans = CGAffineTransformMakeScale(1.5,1.5);
CGAffineTransform rotateTrans =CGAffineTransformMakeRotation(angle * M_PI / 180);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
myView.transform = CGAffineTransformConcat(scaleTrans, rotateTrans);
[UIView commitAnimations];
}
In the above method : replace & with what u want ...
It'll work ,,, surely :)
All the best
You should consider making two copies of the image, rotating one, and masking them both so that they can be placed next to each other in the L shape.
Using this technique, you'll be doing two translations at once (moving the mask and the underlying image) to both images A and T. But, notice that rotation will not be animated. You'll put image T into the rotated state immediately and just reveal it by moving it under the mask (while simultaneously doing the opposite on image A to hide it). So you're not actually combining translation and rotation into one animation, but rather using just translation with a mask on both the original image (A) and a rotated copy (T).
You'll need to mask the left side of one and the right side of the other. The shape of the mask should have an opposite 45 degree angle on both, then you can bring those angled edges together to form the L. As time progress, you just move the mask in each until the first image is totally gone and you're left with your end state.
The masking part is the hard part. See this answer on masking a UIImage with CoreGraphics: masking a UIImage
The mask PNG would basically just be a rectangle with one side at a 45 degree angle. You could create that in the image editor of your choice (Photoshop, GIMP, Acorn).
Note: this approach will create a sharp edge at the corner. The other approach would be to warp the pixels around that corner as they move from the vertical downward motion to the horizontal rightward motion. (I think) This would be much more involved.
I use
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
It's success, but I use "renderInContext:context" get CGImage from context, I found the image effect is not changed !
How can I get this effect image from CALayer?
My Original reply follows bellow. It was valid at the time I posted it, but Apple does not allow the usage of UIGetScreenImage anymore. To the best of my knowledge after the launch of iOS4 there's no alternative how to render layers with 3D transformations + your app will be rejected if you use UIGetScreenImage
From the iPhone developer docs on renderInContext :
Additionally, layers that use 3D
transforms are not rendered, nor are
layers that specify backgroundFilters,
filters, compositingFilter, or a mask
values.
So renderInContext is not the function you need to use to render a layer that has a 3D transformation applied.
Best you can do is call : UIGetScreenImage, which basically will give you a screenshot and you can then extract the image out of this screenshot.