The iPhone Simulator runs this code:
- (IBAction)fontSizeSliderHasMoved: sender;
{
CGPoint contentOffset = self.textView.contentOffset; // we only
use x-value, which is always zero
NSTextContainer *textContainer = self.textView.textContainer;
NSLayoutManager *layoutManager = self.textView.layoutManager;
CALayer *layer = self.textView.layer;
NSRange visibleGlyphRange = [ layoutManager glyphRangeForBoundingRect:
layer.visibleRect inTextContainer: textContainer ];
UIFont *currentFont = self.textView.font;
self.textView.font = [ currentFont fontWithSize: self.sizeSlider.value
];
NSRange a = NSMakeRange(0, NSMaxRange(visibleGlyphRange) );
[ layoutManager ensureLayoutForGlyphRange: a ];
CGRect r1 = [ layoutManager lineFragmentUsedRectForGlyphAtIndex:
visibleGlyphRange.location
effectiveRange:
NULL
];
CGFloat lineHeight = r1.size.height;
CGFloat strangeDiff;
if ( lineHeight < 10 )
{
strangeDiff = 0.9 * lineHeight; // must not be > lineHeight
}
else if ( lineHeight < 90 )
{
strangeDiff = 10 - 0.1 * lineHeight;
}
else
{
strangeDiff = 1; // must
not be negative
};
contentOffset.y = r1.origin.y + strangeDiff; // ← why do I need
this?
[ self.textView setContentOffset: contentOffset animated: NO ];
}
The slider moves between 6 pt and 66 pt.
When I scroll the TextView so that any line is at the top, then using the
slider will keep this same line fixed at the top of the TextView, which is
exactly what I want.
But: why do I need this strangeDiff?
Obviously I am doing something very wrong and silly. But what?
Gerriet.
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]