I want to develop an iPhone application using the utility template, where the flip side is semi-transparent displaying the contents of the main view, flipped horizontally.
Edit: To create the illusion of semi-transparent flip side, I'd display the same content on the flip view as in the main view, but mirror the content and lower the alpha.
Is it possible to display a text using an UILabel, but mirror the text, ie flip it horizontally? Apple dev pages does not give me any help in this issue.
As August said, I'm not sure of your use case on this, but there's a reasonably straightforward way to do it using Core Animation. First, you'll need to add the QuartzCore framework to your project and do a
#import <QuartzCore/QuartzCore.h>
somewhere in your headers.
Then, you can apply a rotational transform to your UILabel's underlying layer using the following:
yourLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);
which will rotate the label's CALayer by 180 degrees (pi radians) about the Y axis, producing the mirror effect you're looking for.
In the Utility template, the flipside isn't shown semi-transparent. This is most likely for performance reasons on the iPhone. I'm not sure there's any value to having your label flipped if it's not providing any functionality.
That said, I'd look into UIView's transform property.
Related
I have an image view that looks like a wheel. This view detects touch events on each of the colored sections.
The problem I have is that when I rotate this wheel, the UILabels on top of the view need to also be rotated so that the text is still horizontal and human readable.
What is the best way to rotate the labels while the parent view is being rotated?
This is what I am trying now and it does not rotate correctly...
CGAffineTransform textTransform = CGAffineTransformRotate(newTransform, newAngle * -1);
Presumably you are applying a rotation transform to rotate the wheel. If the labels are subviews of the wheel view, their centers are pinned in the right places to the wheel (because a view is located in its superview by its center), and they will travel around with it. At the same time, apply the inverse rotation transform to the labels. The rotation takes place around the center of each label. So each label stays in the right place and stays upright.
An afterthought - also make sure you're not using autolayout on these labels. Autolayout breaks view transforms.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UIImageView Transform Scale
I am trying to achieve something similar to the screenshot down below.
I have tried to do this by simply changing the view's frame property and increasing its width and height but it
1) does not really enlarge the view and its subviews it just increases the size
2) It only increases its size from the left so it does not look even
Also is there a way I can have this animated? I could just place it in UIView's animateWithDuration: block right?
There are 2 approaches you can take -
If you are using standard UITableView then simply use Managing the Reordering of Rows
If you are not using UITableView and are doing something more custom with UIViews then
what you need is a property called scale. Scaling a view is done using Core Graphics Affine transforms when you're looking to affect the UIView (as opposed to the layer which use Core Animation transforms).
To scale a view use - this scales the view to 2x.
// 2x
[yourView setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
To translate, use
// Move origin by 100 on both axis
[yourView setTransform:CGAffineTransformMakeTranslation(100.0, 100.0)];
You can also play around with alpha to set it to say 0.5 to give it that extra cool look you have put in the screenshot.
To animate these, wrap them in an animation block. If you want to transform the view with both of these, then you need to concatenate them.
apply a transformation to the view's layer :)
that can be also be animated :) in fact, it implicitly is!
self.view.transform = CGAffineTransformScale(self.view.transform, 2,2);
I have UIScrollView and number of objects (UIView compositions) with UIImageViews inside them. Some of UIImageViews has round border (I use myImageView.layer.masksToBounds = YES; for this). Other has rectangle borders and part of image in them (I use Clip subviews property in Interface Builder for this).
The issue is that I found that clip properties strongly affect the performance while scrolling:
For iPod touch (4th generation) results of profiling:
with enabled clip properties (both or one of them) I have around 30 fps while scrolling
with disabled clip properties I have all 60 fps while scrolling
I really need to clip some images to round bounds and other to rectangle bounds (to show part of image). So, here is my question: what ways there are to improve performance? May be there are low level ways to do it (drawRect: or something), or may be it would be useful to play around alfa masking or I just do something wrong?
When you have graphically intensive masks and things, a simple and easy way to improve performance (often times dramatically) is to set shouldRasterize to YES on the layer for that item:
#import <QuartzCore/QuartzCore.h>
// ...
view.layer.shouldRasterize = YES;
This will rastersize the view into a buffer, so it isn't constantly re-rendered. This will take up a extra memory for each view, so you should really try and recycle/reuse views as you scroll, similar to how a table view does.
For correct behaviour on retina display you also need to set an appropriate value for rasterizationScale:
view.layer.rasterizationScale = view.window.screen.scale; // or [UIScreen mainScreen]
I've had great success with this for things like scrolling photo galleries, where each item had rounded corners, shadows, etc.
I have a UIImageView that I've added a PinchGestureRecognizer to. Currently, the image is resized nicely when pinching, but I want to be able to resize the image without maintaining the aspect ratio. So if the user pinches horizontally, the image view's width would enlarge; if they pinch vertically, the height would enlarge and so forth.
Can anyone give me a hint on how I could do that please?
Write a custom gesture recognizer that requires two fingers to be on screen.
Once both fingers are on screen store their offset to the imageView's border in some UIEdgeInsets.
In touchesMoved, check if both fingers are onscreen: if so, calculate the new frame by applying the edgeInsets in the current touch position.
Header: click
Implementation: click
Works well and feels more natural than other implementations I've seen.
You would need to do the touch handling yourself as UIPinchGestureRecognizer only supports one scale which has no concept of being pinched horizontally or vertically.
You could create your own subclass of UIGestureRecognizer (see here for docs) which looked at the horizontal and vertical separation of the touch points to determine 2 different scales. It should be fairly straightforward to create I would have thought. Just look at the initial touch points and then when they move, calculate the difference in the current separation of the touches to the initial separation of the touches, in both the vertical and horizontal directions.
I'd like to get some tip about how implement a PDF View that scrolls horizontally.
I know how implement a PDF reader using UIWebView, but just with vertically scroll.
I've done this. The code was private for a paying customer, so I can't share it directly, but the basic idea is to write:
One UIView subclass that renders a single page of a PDF, using a CGPDFPageRef and the CGPDFDocument* and CGContextDrawPDFPage families of functions. It helps a great deal for this view to return [CATiledLayer class] from the layerClass class method, and to set the layer's levelsOfDetail and tileSize properties appropriately. Mine also implements sizeThatFits to return the page size plus a small gutter, and renders a subtle dropshadow around the edge of the pdf page.
Remember that UIKit drawing is upside-down from CG drawing; so do a CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); before painting.
One UIView subclass containing and laying out (and being delegate for) a UIScrollView in paging mode (the main horizontal pager), and an individual UIScrollView for each page, each containing one of the above views (for zooming into individual pages.) Nested scroll views is Apple's explicitly endorsed way of doing this sort of thing. This view will need to lay out the pages how you want them; presumably in one long horizontal strip, each zoomed to a fitting size.
If you don't need page zooming, you can skip the nested scroll views and lay out the page views directly in the horizontal scroller.
TL;DR: Unfortunately it's not as simple as tossing it in a UIWebView; but it is doable, and the straightforward approach does work.
I found an open project with this feature =D
https://github.com/iamruinous/Reader
I found an open project with this feature
https://github.com/vfr/Reader