Search code examples
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

when I say I wanna remove it means I wanna remove this virtual places (in green and blue ) totally and not only remove the FocusGuid layout from the view

I already managed to remove the FocusGuide by using

MyfocusGuide.preferredFocusedView = [self preferredFocusedView];

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


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