I have a custom view which needs to be relaid on orientation change. My UIView code can correctly redraw for the any orientation as it express itself in screen frame size.
But how do I get the loadView method to run on orientation change for the right view to get drawn ?
I put [self.view setNeedsDisplay] in the following rotation handling methods with no luck.
willRotateToInterfaceOrientation:duration
didRotateFromInterfaceOrientation:
Any suggestions would be most welcome.
loadView actually causes the view to be completely re-created from scratch. It should be sufficient to call setNeedsDisplay in didRotateFromInterfaceOrientation on the view that needs to redraw.
If you have to change the layout of your views upon rotation, do so in willAnimateRotationToInterfaceOrientation (so the changes get animated), and/or set the autoresizingMask property to the combination of UIViewAutoresizingMask values that suits your needs.
Related
I have a UIViewController being presented with a UIViewControllerAnimatedTransitioning object to do the animation. The animation has a collection view cell expand and fade out as the new view controller's view fades in, expanding in the same way. So it looks like you have an expanding cell that transforms into the new view controller. But weirdly enough, the subviews of the cell get transformed in weird ways when they use auto-layout. When I don't use auto-layout, this doesn't happen. What might be the issue?
Try adding your cell to [[transitionContext containerView] superview] in - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext, instead of [transitionContext containerView]
For some reason this worked for me
I got a problem with Cocoa and its View redraw hierarchy.
I'm currently testing displaying (audio) levels in a meter style control and I'm using the MeteringView class from MatrixMixerTest example project from apple. This class is drawing the meter and only drawing the difference what got changed which looks like a very efficient class.
My project is splitted into 2 splitviews, in some are NSCollectionViews (Scrollview, Clipview) and in others are only static views. If I add the meter to those "static" views they work fine when these views call setNeedsDisplay:YES. If a meter is added to the view of a CollectionView Item it gets rendered, but loosing its drawn "old level" parts and its corners/background. I think this happens because the CollectionView item gets also called to be redrawn (which has a background image) and everything is gone. It is drawing some parts whats currently changing (the drawing works).
Is there a way to prevent the Item itself to be redrawn? Or, I dont know why it is not happening in those static views, because those views also have background images but do not draw over the meter.
Are there some tricks or whats different in a CollectionView than in a "normal" view?
EDIT: After reading about isOpaque (MeteringView isOpaque = YES) means it should not call the parent views drawRect if set to yes. Well that works for the static views, those MeteringViews do not call parents drawRect, but those in a CollectionView do however. I dont know why.
EDIT 2: I gave this topic another title, because isOpaque=YES in MeteringView is not stopping calling the parents drawRect in a CollectionView, in a normal view it is working. Are there some things to know about? I have to stop redrawing the CollectionView Item because thats the problem.
Thanks in advance guys
Benjamin
isOpaque is just hint to the system. It does not prevent other views from drawing their contents, it only means that it can sometimes skip making other views update their contents.
If your view is opaque, it should draw itself as opaque and completely fill its bounds.
I have a NSView as the documentView for a NSScrollView. I also have a NSImageView as a subview of the NSView. The image dynamically changes size so the scroll bars become active/inactive at various times. Once the image has changed, I'd like to scroll to a certain point on the image. From within the NSView's drawRect: method, I call
[[myScrollView contentView] scrollToPoint: myPoint];
The scroll bars update and the image appears as I'd like, but as soon as the image is scrolled, a double image appears or parts of the image get cut off. Any help would be appreciated. Thank you.
Sounds like you might want to turn off the "Copy On Scroll" behavior option of the NSScrollView either in Interface Builder or programmatically.
From Scroll View Programming Guide for Mac OS X: How Scrolling Works:
The NSClipView class provides low-level scrolling support through the
scrollToPoint: method. This method translates the origin of the
content view’s bounds rectangle and optimizes redisplay by copying as
much of the rendered document view as remains visible, only asking the
document view to draw newly exposed regions. This usually improves
scrolling performance but may not always be appropriate. You can turn
this behavior off using the NSClipView method setCopiesOnScroll:
passing NO as the parameter. If you do leave copy-on-scroll active, be
sure to scroll the document view programmatically using the NSView
method scrollPoint: method rather than translateOriginToPoint:.
I am implementing printing in my document-based Cocoa application, and I'm wondering if anyone can help me out with this task.
I have to use a custom pagination scheme because the main view works in ways that normal pagination methods would not support. This works, however my view ends up being too big for the paper size most of the time. Tiling the view across multiple pages is not acceptable for my app, I would like to have my custom pagination work in the same way the NSFitPagination method works; if the view is too big for the page, it will resize the view by scaling it.
I thought I could do this by simply overriding the drawRect: method of my view and applying a transform to the current graphics context before it is drawn. However, it appears that printing mechanism calls the drawRect: method independently for each individual subview of a view that's being drawn, so applying a scale to the drawRect: of the superview doesn't work.
Any thoughts?
I solved this by instead of adding my view as a subview of the view to be printed, I overrode the drawRect method of the view being printed and manually set up a transformation and scaling and called drawRect on the view to print as a subview.
i have a CALayer with a custom draw method I've added to my view's base layer. I set needsDisplayOnBoundsChange to NO. However, when I resize the parent view's frame, the layer's drawInContext: is getting called continuously. I'd like the contents to scale while the resize is occurring. Any clues?
Interesting, I have a case where I have a CALayer that correctly scales its contents until I call setNeedsDisplay on it to redraw its contents. One thing that may be different is that in my case the layer is being drawn by its delegate and not by a subclass of CALayer. Another thing that may be different is that this is on iOS and not OSX (I don't know which you are using in this case). It is possible that there could be behavior differences between subclasses and delegate drawn layers and/or iOS and OSX.
Another thing to note is that needsDisplayOnBoundsChange is documented to be NO by default, so one should not need to set it. I am not specifically setting needsDisplayOnBoundsChange on my layer.
You could try using a delegate to do the drawing to see if that makes a difference. Note that a UIView cannot be a delegate to a CALayer. In my case I made a simple delegate object that forwards the draw call to my view.