Search code examples
focustvos

Remove PreferredFocusedView tvOS


I have a code in Objective C Working on AppleTV which I have used a PreferredFocusedView Constraints then I wonder how can I remove this constraints later without changing the view,

enter image description here

The Goal: I wanna remove the Buttons (in green and blue ) totally and not only remove the FocusGuid layout from the view on certain condition only happened when focusing on some other buttons.


Solution

  • The solution I have found is to use the new array UIFocuseEnvironment with tvOS 10.0 that make it easy for me

    - (NSArray<id<UIFocusEnvironment>> *)preferredFocusEnvironments  //Called By [self setNeedsFocusUpdate]
    {
        if (CONDITION)
        {
            return @[BUTTON1, BUTTON2];
        }
        else
        {
            return nil;
        }
    }