IKImageBrowserView does not refresh unless user scrolls - cocoa

We've got an IKImageBrowserView that displays a bunch of images. We asynchronously download those images in the background and cache them to disk. We then notify the IKImageBrowserView that the imageRepresentation has changed using KVC. e.g. didSetValueForKey:#"ImageRepresentation". However, it looks like IKImageBrowserView will only refresh itself to load the recently downloaded images if user scrolls the view (We embedded IKImageBrowserView inside an NSScrollView). Why is this the case? Is there anyway to force IKImageBrowserView to redraw a certain cell or all visible cells without waiting for user to scroll the view?

Try using the reloadData method.
[browser reloadData];
I've got a similar situation in which I am using a IKImageBrowserView to view images that are downloading. In my case, I create the initial set of images with a placeholder image and then download the image. As each comes in, I update the data source entry with a different image, increase the image version number, then use the reloadData method on the browser. I also turn off animations so that the user doesn't see the entire browser redraw, only the images that have been updated.
- (void) setImage: (NSImage *) image
{
[img release];
img = image;
[img retain];
imageVersion++;
}
The above is a setter method for my data item that implements the informal protocol.
https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/IKImageBrowserItem_Protocol/IKImageBrowserItem_Reference.html

Related

Display UIImageView contained in UITableViewCell fullscreen with animation when tapped

I've an UIImageView inside an custom UITableViewCell and want it to display fullscreen when I tap on it. I've attached a UITapGestureRecognizer to the UIImageView and the image already resizes. The problem I have right now is that the image only moves inside the cell it is contained in, but it should in fact move out of it. I'd also like to put a black background behind the image.
Any ideas on how to achieve that?
I would say the culprit is most likely either the cell, or the cells content view is clipsToBounds enabled. Setting [cell setClipsToBounds:NO]; should solve this problem.
However, if you're willing to take a new approach to this, it may be beneficial to instead of growing the cells imageView, add a new image above the tableview in the same location as the cell's image view and then grow that. This way you wouldn't have any undesirable behavior like being able to scroll the image view away because the table is still scrollable.

UIImageView not updating image when displayed in a UIScrollView

I am new to Xcode and objective C so the problem I have hit may be a simple one but I haven't been able to find an answer yet so thanks for any help you can give.
I am trying to write a simple app that takes a picture from the camera and displays it in a UIImageView. This all works fine if the UIImageView control is just placed in the UIView control (using the interface builder). The code I use to set the image to the control is
[self.imageViewOSFCorner setImage:image];
However I need to display several images an wanted the user to be able to scroll up and down the page. So I created a UIScrollView in the interface builder that is the size I need and placed all the controls in that. Then in the viewDidLoad method I placed the following code to display the UIScrollView
self.scrollView.contentSize = self.scrollView.frame.size;
self.scrollView.frame = self.view.frame;
[self.view addSubview:self.scrollView];
This works in that you can now scroll the page and see all of the UIImageView controls, and when I press the button it launches the camera, but now after taking the picture it doesn't display the image into the UIImageView. If I take the UIScrollView away it works again (but obviously doesn't scroll) - I am guessing I am doing something silly, is there a function I need to call to update the UIScrollView?
As an aside I originally tried to use the code
self.imageViewOSFCorner.image = image;
to display the image but this wouldn't display the image and had to use
[self.imageViewOSFCorner setImage:image];
can someone tell me why the first method didn't work?
Thanks
Will
May be useful:
self.scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width*num,view.frame.size.hight );
num is your number of all image
Ok it is working now, I must have done something stupid when creating the controls into the UIScrollView since I have started from scratch again in the interface builder and now it all works.

How to temporarily disable UIView background image from responding to mouse clicks in Interface Builder?

I have a UIView background image that I want to use for my view.
Now, on top of this image, I want to have buttons and position them relative to what I see in the image.
The problem is, these buttons were already added to the view before the background image was added. So now when I put the background image, entire view is background image and I am unable to access the buttons underneath it in Xcode.
Is there a way to tell Xcode that I am not interested in the UIView but actually the buttons that appear underneath it?
Check - (void)sendSubviewToBack:(UIView *)view in UIView
Would be something like
[self.view sendSubviewToBack:backgroundImageView];

Cocoa - NSScrollView with large number of items

I have an NSScrollView to which I'm adding a bunch of NSViews that have an NSImage subview. Basically it is a long row of thumbnails contained in a scroll view.
Everything works great... until there are thousands of images in the scroll view (since there is no creation of separate thumbnail images, the images are large but downsized to thumbnail size).
It seems the best thing to do would be to dealloc the images that aren't currently shown in the scroll view, and load them back into memory as they come into view. Does NSView support this type of notification (similar to viewWillAppear: and viewWillDisappear: on iOS).
Also, in ARC mode, how do explicitly tell the OS to unload an image? Will setting the NSImage* to nil do the trick?
I think the best approach would be to create a custom NSView subclass that owns the image subviews:
Code your drawRect: method so that only those images that intersect with the dirtyRect are drawn.
Embed your custom view as the subview of the NSScrollView.
As images are added/removed (if this is even possible) you'll want to recalculate your view size and call [super setFrameSize:] so the scroll view knows to change the scroll bar length etc.
Override setFrameSize to re-layout and modify the size, on the way through, if you change the layout when the view is resized (if you have the concept of layout in your view).
You don't say in your question what issues you are facing; are they memory or performance (or both)? I don't think continually releasing and reallocating the subimages will help you either way.

How do I embed a WebView in an NSScrollView?

So I have a project that has some content being displayed in a WebView and I want to stick above that. I want the header to scroll with the WebView content. Now, WebView generally wants to do it's own scroll handling but you can tell it not to using:
[[webView mainFrame] setAllowsScrolling:NO];
which successfully makes the WebView's scroll bars not appear. However, despite the fact that it's embedded in an NSScrollView, the NSScrollView's scroll bars never activate. I can only conclude that the WebView needs to be told to resize, but I can't figure out how to do that. I have tried the following:
NSRect webViewBounds = [webView bounds];
[webView setFrameSize:webViewBounds.size];
but that doesn't appear to work either.
Any suggestions?
Alternative solution: What about expressing the header in HTML/CSS/JavaScript, and putting the real content in an iframe? You can traverse the frame hierarchy to find the WebFrame object for that frame, and use the DOM (perhaps wrapped by an object of your own) to control the header.
I had a quick look at the docs for this, probably a silly question; after you change the frame size are you sending a setNeedsDisplay message to the view?
The bounds and frame in your code should have the same size. Setting one to the other changes nothing.
Today I played a little bit with the WebView class. With my approach you wouldn’t have to add your header to the HTML code. Registering for a notification gives you a starting point:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(webViewDidScroll:)
name:NSViewBoundsDidChangeNotification object:nil];
Then you can check the class of the notification sender (let’s assume you have only one WebView):
- (void)webViewDidScroll:(NSNotification *)aNotification
{
if ([[aNotification object] isKindOfClass:NSClassFromString(#"WebClipView")])
{
// Do whatever you like; scroll your header etc.
}
}

Resources