Custom Layer Class

Hi, i want to implement uiview with custom Catiledlayer for that it should be add class method layerclass like below:

+layerClass
{
    return [CATiledLayer class];
}

How can be done in moe?

What excactly are you trying to achieve? Please provide us more details, maybe there’s a better solution for what you are trying to do.

Hi Christian
I want to render huge uiview with custom drawing which use drawrect method of uiview in uiscrollview

In the default uiview use calayer as layer class, for that huge uiviews catiledlayer is recommended as i understand
: https://stackoverflow.com/questions/22961577/what-is-the-best-way-to-show-large-uiview-on-uiscrollview

to change uiviews default layer class i have to implement layerclass method, but there is no method in uiview.java class

By the way, Glkview class extends from uiview and it has layerclass method. (But that class is depricated)

Hi there!

I’ve had a look into the Java binding class UIView.java and there’s actually a layerClass method.
But as it seems it is static and therefor cannot be overridden by any sub class.

So probably you want to sub class UIView in ObjectiveC and create a custom UIView binding by copying the generated UIView java binding and remove / add respective @Annotations (removing @Generated on Type and adding @RegisterOnStartup. :arrow_left: not a 100% sure about these two, maybe @Noisyfox can say more about that :sweat_smile: )

Christian
I will try to generate custom Objective-C and bindings.
Thanks.

I think all you need to do is something like

public class HugeView extends UIView {

    // Some other codes

    @Selector("layerClass")
    public static Class layerClass() {
        return Class.fromJavaClass(CATiledLayer.class);
    }
}

You don’t need to override the static method, just declare a new static method with the same selector and MOE should be able to take care of it.

This is similar to how you declare the alloc() method in your classes: https://github.com/multi-os-engine/moe-samples-java/blob/moe-master/TicTacToe/ios/src/main/java/org/moe/samples/tictactoe/ios/TicTacToeViewController.java#L56-L58

1 Like

Great solution :slight_smile:
Thanks again Noisyfox. :clap:

1 Like

Didn’t know about that nice sugar! Thx :slight_smile: