objective c - NSImageView resized with image size -
i'm new obj-c/cocoa programming , facing problem nsimageview.
goal create app allow user put image on drag&drop.
the problem following : when we're dropping image larger window, resizes window image size, i don't want that !
put nsimageview nsscrollview part of image must showed , user move sliders view entire 1 (or resize window), that's want..
here xib hierarchy (concerned part) :
- view
- nsscrollview
- view
- nsimageview
- view
- nsscrollview
in code of nsimageview, have (about problem) :
[self setimagescaling:nsscaleproportionally]; [self setimage:newimage];
note: sliders seem move view , not image
note2: can't resize window lower size image
i have horrible aversion nib files , prefer things programmatically whenever possible i'm not that... here's little listing little nsscrollview test app coded similar. non-self-contained thing mentioned in code chunk window
name, refers nswindow *
window created. , self
here refers controller object.
nsimage * myimage = [nsimage imagenamed:@"myfilename.png"]; nsrect imagerect = nsmakerect(0.0,0.0,myimage.size.width,myimage.size.height); self.myimageview = [[nsimageview alloc] initwithframe:imagerect]; self.myimageview.bounds = imagerect; self.myimageview.image = myimage; self.myscrollview = [[nsscrollview alloc] initwithframe:[window.contentview frame]]; self.myscrollview.hasverticalscroller = yes; self.myscrollview.hashorizontalscroller = yes; self.myscrollview.documentview = self.myimageview; self.myscrollview.bordertype = nsnoborder; self.myscrollview.scrollerstyle = nsscrollerstyleoverlay; window.contentview = self.myscrollview;
i know that's perhaps not solution looking maybe helps debug? in particular, didn't funny nsimageview
besides give frame, bounds rectangle, , nsimage *
, don't think need worry scaling parameter per se -- in fact, if want image full-sized , scroll around it, want nsimageview
's frame same size image doesn't have scale @ all. maybe that's problem -- frame small? ok nsimageview frame bigger window -- that's lets scroll around it.
Comments
Post a Comment