Apple chief executive Tim Cook has publicly acknowledged his sexuality, saying he wants to try to help people struggling with their identity.