focustvos

Remove PreferredFocusedView tvOS


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

enter image description here

The Goal: I wanna remove this virtual places (in green and blue ) totally and not only remove the FocusGuid layout from the view

Update: I already managed to remove the FocusGuide by using

MyfocusGuide.preferredFocusedView = [self preferredFocusedView];

But still, those buttons (green and blue) exist and in action every time I move to their location.

Note: I have already answered this question but i guess the way to do it have changed a lot with the newer versions of TVOS


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;
        }
    }