Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4351] iOS: Add "canScale" to ImageView for Parity with Android

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionWon't Fix
Resolution Date2011-12-05T12:26:53.000+0000
Affected Version/sRelease 1.7.0
Fix Version/sSprint 2011-26, Sprint 2011-49
ComponentsiOS
Labelsn/a
ReporterDawson Toth
AssigneeBlain Hamon
Created2011-06-08T10:04:12.000+0000
Updated2017-03-03T22:28:59.000+0000

Description

Feature

The "canScale" property exists on Android, but not on iOS. It lets you pinch around an image.

Workaround

On iOS, you can dump the image in a scroll view. But it takes quite a bit more code to get it to work properly.

Sample Code

The following shows a large remote image (~500kb). It may take a moment for the sample to come up. Feel free to download the image locally to speed it up. It demonstrates the Android and iOS approaches to a scalable image.
var win = Ti.UI.createWindow({ backgroundColor: '#000' });

var image = Ti.UI.createImageView({
    image: 'http://appc.me/content/appceleratorHat.jpg',
    width: 'auto', height: 'auto', canScale: true
});
if (Ti.Android) {
    // this simple code works in Android
    win.add(image);
}
else {
    // but iOS requires all of this
    var scroll = Ti.UI.createScrollView({
        contentHeight: 'auto', contentWidth: 'auto',
        maxZoomScale: 1, minZoomScale: 0.16
    });
    image.addEventListener('load', function() {
        scroll.zoomScale = 0.16;
    });
    scroll.add(image);
    win.add(scroll);
}
win.open();

Associated Helpdesk Ticket

http://appc.me/APP-121155 http://appc.me/APP-422217 http://appc.me/APP-768251

Comments

  1. Blain Hamon 2011-06-22

    The native iOS doesn't have a 'canScale' property in UIImageView, and implementing this would have a significant performance and memory hit for *any* image view as we'd be manually stuffing it into the scroll view, even *if* canScroll was false.
  2. Dawson Toth 2011-11-10

    Pull request for this functionality was sent in by Dohko from the community: https://github.com/appcelerator/titanium_mobile/pull/426/files
  3. Stephen Tramer 2011-12-05

    Need to re-evaluate.
  4. Blain Hamon 2011-12-05

    Rejecting request now with the text: The canScale property is that, in Android, you can zoom and pan an image within its view. To have something similar, it'd require embedding a UIScrollView into the view hierarchy of each image view, which is incredibly expensive. This code appears to instead disable the proper scaling of the image inside its view, meaning it will ignore the size specified by the view, which is NOT what canScale is meant to do.
  5. Blain Hamon 2011-12-05

    Implementing such would be rather expensive performance-wise on each image view, and may lead to other regressions (IE, an imageview with canscale would be unpredictable within a table view)
  6. Lee Morris 2017-03-03

    Closing as duplicate.

JSON Source