Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:15:43+00:00 2026-05-30T21:15:43+00:00

I cannot find any equivalent binded method for CALayer’s initWithLayer:(layer) selector that I can

  • 0

I cannot find any equivalent binded method for CALayer’s initWithLayer:(layer) selector that I can override.

Looking at the Monotouch Assembly, the selector initWithLayer is bound to the default constructor like so:

[Export ("initWithLayer:")]
    public CALayer (CALayer other)
    {
        if (base.GetType () == typeof(CALayer))
        {
            Messaging.intptr_objc_msgSend_intptr (base.Handle, CALayer.selInitWithLayer, other.Handle);
        }
        else
        {
            Messaging.intptr_objc_msgSendSuper_intptr (base.SuperHandle, CALayer.selInitWithLayer, other.Handle);
            this.Clone (other);
        }
    }

However I need to be able to override the initWithLayer in order to animate my custom property in my CALayer class. (As specified in my previous question Animate a custom property using CoreAnimation in Monotouch? )

Was this done by mistake, or am I incorrect in saying that it’s not possible to override a default constructor?

Apples Documentation states that the only use of initWithLayer is to create shadow copies, its not for initializing a layer, which makes me thing it might be a Monotouch bug

Apple Documentation

initWithLayer: Override to copy or initialize custom fields of the
specified layer.

  • (id)initWithLayer:(id)layer Parameters layer The layer from which custom fields should be copied. Return Value A layer instance with any
    custom instance variables copied from layer.

Discussion This initializer is used to create shadow copies of layers,
for example, for the presentationLayer method.

Subclasses can optionally copy their instance variables into the new
object.

Subclasses should always invoke the superclass implementation

Note: Invoking this method in any other situation will produce
undefined behavior. Do not use this method to initialize a new layer
with an existing layer’s content. Availability Available in iOS 2.0
and later. Declared In CALayer.h

EDIT:

The reason I need to override this method is the CoreAnimation framework calls this method to create its own internal copy of my layer. I need to be able to override it to include the new properties i’ve added to my layer, so that CoreAnimation knows to tween my property values over the course of the animation. I will not be calling this myself. This is why I cant simply call Clone()

I’ve tried to add a modification to Rolf’s code, but it still doesn’t get called:

//Needed to do this as sel_registerName is private
[DllImport ("/usr/lib/libobjc.dylib")]
    internal static extern IntPtr sel_registerName (string name);

    static IntPtr selInitWithLayer = sel_registerName("initWithLayer:");

    [Export ("initWithLayer:")]
    public CircleLayer (CALayer other)  //changed SuperHandle to other.SuperHandle as using this.SuperHandle gives me an object reference required error.
        : base (Messaging.intptr_objc_msgSendSuper_intptr (other.SuperHandle, CircleLayer.selInitWithLayer, other.Handle))
    {
        // custom initialization here
        Console.WriteLine("Got to here");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:15:44+00:00Added an answer on May 30, 2026 at 9:15 pm

    I cannot find any equivalent binded method for CALayer’s initWithLayer:(layer) selector that I can override.

    Looking at the Monotouch Assembly, the selector initWithLayer is bound to the default constructor like so:

    A little bit of terminology: public CALayer (CALayer other) isn’t a default constructor – a default constructor doesn’t have any parameters.

    However I need to be able to override the initWithLayer in order to animate my custom property in my CALayer class. (As specified in my previous question Animate a custom property using CoreAnimation in Monotouch?)

    That question doesn’t say why you need to override the initWithLayer constructor. I did find this though: Why animating custom CALayer properties causes other properties to be nil during animation?, which seems to be what you’re trying to do. In this case I think there is an easier way to accomplish your need: you just need to override the Clone method in your custom CALayer class, and do the proper initialization there.

    Was this done by mistake, or am I incorrect in saying that it’s not possible to override a default constructor?

    Technically, in C# you don’t override a constructor. In your base class you provide your own constructors, and all of them must call one constructor in the immediate base class (this may be done implicitly by the compiler in some cases).

    That said, in MonoTouch you can provide a constructor in your class that does everything you want (I still believe you should try the Clone approach first though):

    public MyCALayer : CALayer {
        [Export ("initWithLayer:")]
        public MyCALayer (CALayer other) : base (other)
        {
            // custom initialization here
        }
    
        public override void Clone ()
        {
            // copy any code that you care about here.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cannot find any developer information about this function. I just know that it's suggested
I cannot find any method like char c = 'c'; preparedStatement.setChar(1, c); How to
I'm working on a project and cannot find any documentation that verifies signal/thread behavior
I cannot find any statement that specifies whether it would be safe to get
Cannot find any example on Google.
This is but a curious question. I cannot find any useful links from Google
Searching for possible ways to get cookie with httpOnly enabled, I cannot find any.
Is there any known attack on this modified version of Yahalom? Cannot find anything...
HEllo , i can not find any way to get horizontal or/and vertical resolution
Is there any method equivalent to Rails / Flask ’s url_for on Express.js ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.