I use this code to resize the stage. On desktop everything is fine but the Ipad safari and chrome crashes. I tried to delete some other stuff and figured at that it can only be the resize that forces the crash. Strange allthough that this code worked a while ago and I was very surprised that it doesn't now. Anyone got an idea or maybe another method of resizing?
Thanks in advance
window.onresize = function(event) {
stage.setWidth(window.innerWidth);
stage.setHeight(window.innerHeight);
stage.draw();
}
The problem is that you're triggering stage.draw() hundreds of times per second. KineticJS v4.5.5 will resolve this problem with the stage.batchDraw() method, which hooks draws into the animation engine for performance. This way, if you call stage.batchDraw() hundreds of times per second via mousemove, the stage will only get drawn about 60 times per second.
It might be because the iPad doesn't support innerWidth and innerHeight (I know not all mobile devices support it), so your code could be crashing by trying to set the stage width and height to an undefined number.
You'll have to use an alternative to setting the stage to the screen size.
You could try something like:
if (window.innerWidth) {
width = window.innerWidth;
height = window.innerHeight;
} else {
width = screen.width;
height = screen.height;
}
If this doesn't work for you, you'll have to look into other ways to handle different screen dimensions. I came across this article a while back: http://tripleodeon.com/2011/12/first-understand-your-screen/
Related
I create tests using Appium+Python to test IOs app.
I want to scroll the page.
Here is the code
def scroll_page(self):
action = TouchAction(self)
action.press(BrowsePageElements.firs_element_to_scroll(self)).
move_to(BrowsePageElements.second_element_to_scroll(self)).perform()
When I'm trying to run this function, I get an error
error screenshot
Could you help me to find out, how to fix this error?
Appium Python has a native scroll function. It works for both Android and iOS.
driver.scroll(origin_el, destination_el, duration=None), where duration is an optional argument. This function scrolls origin_el to the location of destination_el.
Link to scroll source code
The Appium documentation is rather spotty and needs updating. However, the source code is documented well enough to understand and learn the program.
This currently works for me:
...
SCROLL_DUR_MS = 3000
...
window_size = self.driver.get_window_size()
self.scroll_y_top = window_size['height'] * 0.2
self.scroll_y_bottom = window_size['height'] * 0.8
self.scroll_x = window_size['width'] * 0.5
...
def scroll_up(self):
self._y_scroll(self.scroll_y_top, self.scroll_y_bottom)
def scroll_down(self):
self._y_scroll(self.scroll_y_bottom, self.scroll_y_top)
def _y_scroll(self, y_start, y_end):
actions = TouchAction(self.driver)
actions.long_press(None, self.scroll_x, y_start, SCROLL_DUR_MS)
actions.move_to(None, self.scroll_x, y_end)
actions.perform()
It scrolls slowly over 3s because I want it to be controlled, but you could shorten SCROLL_DUR_MS (the duration of the scroll action in milliseconds) if you want something more zoomy. I also went away from using elements as the start and/or end points because I wanted something general that would work with any screen content.
For scroll_y_top and scroll_y_bottom I picked 20% in from the top and bottom of the screen just to make sure I wasn't hitting anything at the borders (like the navigation bar at the top of iOS Preferences or an info bar at the bottom of the app I was working in). I also ran into a "bug" where it wasn't scrolling when I left scroll_x as 0, but it turns out that it wasn't registering the left edge as inside the scrolling area for the app I was working in.
Hope this helps.
In the past when i've run into issues scrolling for one reason or another, I've simply swiped using coordinates to scroll down the page.
self.driver.swipe(100, 700, 100, 150)
I'm having some problems with how long a Titanium app I am making
takes to load a ScrollView.
Titanium SDK: 3.3.0.GA
I decided to run a test, comparing how long it would take for a titanium app
to load a similar view, and a native built version (iOS).
The test was loading 1000 textfields into a ScrollView.
For the natively built app, it took about 0.850 seconds to load
on an iPad mini (based on 3 trials).
For the titanium built app, it took about 59.3 seconds to load
on the same iPad mini (based on 3 trials).
Obviously, this is a significant difference. My code for the
Titanium build is below. Is there something I'm missing? Some option that
is making the ScrollView so slow?
59 seconds compared to 0.850 is pretty significant.
index.xml
<Alloy>
<Window class="container" >
<ScrollView id="scrollView" layout="vertical"></ScrollView>
</Window>
</Alloy>
index.tss
".container": {
backgroundColor:"white"
}
index.js
var startTime = new Date();
startTime = startTime.getTime() / 1000;
$.index.addEventListener('postlayout', calculateTimeToLoad);
loadThousandTextFields();
function calculateTimeToLoad() {
$.index.removeEventListener('postlayout',calculateTimeToLoad);
var endTime = new Date();
endTime = endTime.getTime() / 1000.0;
Ti.API.info("Total time taken:" + (endTime - startTime) + " seconds");
}
function loadThousandTextFields() {
for(var i = 0; i < 1000; i++) {
$.scrollView.add(Ti.UI.createTextField({
hintText: "Hint text"
}));
}
}
$.index.open();
Note: I am aware of Titanium's ListView, however, based on my experiments with it, it looks like it won't
work too well with the app I am making, as I need interaction between my various components and the ability to change
them based on that interaction. (For example, having a switch that, upon being turn off, would
clear a nearby textfield, or fill it with some text. ListViews seem to be very slow in updating views like that. If I'm wrong, please let me know).
Further Note: I tried running the same test on titanium sdk 3.2.3, and it took about 6 seconds as opposed to 59, on the same iPad mini. However, in the app that I am making, the scrollview actually took longer to load.
Thanks
In Mobile Application development. You have always remember Use low Memory or need to always clear unused memory.
Here you add approx 1000 textView at a time. That's why. your app going slow.
Please you try this Reference. In this example. when you scroll you table view then it will add next some row. and this will adding one by one according your display.
Example :- https://gist.github.com/mschmulen/805283
I have a UIViewController that after asynchronously loading some data needs to resize some child views (Some UITableViews, and some UIScrollViews). This works just fine in the simulator, but on an actual device, it hangs for a long time (as much as 30 seconds in one case). I think the problem is that it wants to recalculate everything after each changed to the child view and I would like to be able to tell it to defer any recalculations until I've resized everything, but I'm drawing a blank on finding a way to do that. Is there a mechanism to do this?
So what I'm doing is something like this (I'm using C# with Xamarin but input in Obj-C would also be appreciated!):
// Need to suspend layout here...
MyTable.Frame = new RectangleF(...);
SomeOtherTable.Frame = new RectangleF(...);
ScrollView.ContentSize = new SizeF(...);
AnotherScrollView.ContentSize = new SizeF(...);
AnotherScrollView.Frame = new RectangleF(...);
// Ok - now you can redraw!
Update: Jacob's suggestion of disabling animation didn't seem to help, but I think I've isolated the problem to the table resizing. They seem to have the biggest impact on performance, but I'm not sure why, or how to mitigate the problem. I may follow up with a separate question on that.
I am using a parallax effect with javascript but I'm having issues with iPad.
I know the "$(window).scroll" is not triggered on webkit touch devides - only when we release the screen - so i'm using:
window.addEventListener("touchmove", triggerScroll, false);
function triggerScroll(event)
{
var scrollTop = $(window).scrollTop();//event.touches[0].pageY; //window.pageYOffset();
$("#allCanvas .divCanvas").each(function(index, element) {
var speed = $(element).data('speed');
var initialTop = $(element).data('initialtop');
$(element).css('top', initialTop-(scrollTop*speed));
});
}
The problem is that it flickers the .divCancas a few pixels to the top or bottom depending if I'm scrolling to top or down.
I tracked the TOP value passed on $(element).css('top', initialTop-(scrollTop*speed)); and it's every time correct. The correct "TOP" value, eventhough webkit move it for a few milleseconds to the wrong position.
I tried also:
-"margin-top" rather than "top" with no difference.
-Removing all other objects and making the ".each" loop through only one div, so I guess is not a jQuery performance issue.
Has anyone came across this problem?
Many thanks
Diego
Maybe try using some of the -webkit css animation features... these run very smoothly on iOS devices. Here's a great demo of that (webkit only): http://jibjub.com/demo/HTML5/cube.html
This is a curious one.
I have an IBOutlet UIScrollView playScrollView whose height is exactly 1/3 of it's contentSize's height. The app is in landscape. I call this code...
[playScrollView scrollRectToVisible:CGRectMake(0.0f, page * PLAY_VIEW_PAGE_HEIGHT,
480.0, PLAY_VIEW_PAGE_HEIGHT)
animated:animated];
... (the int page ranges from 0 to 2) to start on page 1 (displaying the middle third) then go up or down as needed when the user presses buttons.
This works fine for iOS4 both device and simulator, and has been live on the app store for months with no problems. Even iOS5 devices are fine with existing builds, it was only when the app was recompiled for iOS5 that it stopped working correctly on iOS5 devices.
Since updating to XCode 4.2, This doesn't work for iOS5. It goes one page too low, showing the bottom page when it should show the middle. I can get the code to work for iOS5 (device and simulator) by changing page to (page-1)...
[playScrollView scrollRectToVisible:CGRectMake(0.0f, (page-1) * PLAY_VIEW_PAGE_HEIGHT,
480.0, PLAY_VIEW_PAGE_HEIGHT)
animated:animated];
...but of course this breaks iOS4, which works fine with the old code, but gets stuck one page too high with this new code. iOS4 and iOS5 are exactly PLAY_VIEW_PAGE_HEIGHT out-of-step (288 pixels, a third of the height of playScrollView). The same thing happens if I use setContentOffset: instead.
One other curious thing, probably the key to this. If I don't do the scrollRectToVisible at all, then iOS4 sits at the top of playScrollView, wheras iOS5 shows the middle third, (ie PLAY_VIEW_PAGE_HEIGHT pixels down).
I could detect the iOS and use different code for each, but that's a horrible kludge. If it's an iOS5 bug and they fix it in a future release, that would break the live app.
Has anyone any ideas, or noticed anything similar? Thanks.