“As a gay man, San Francisco has a meaning in terms of a place where you can be yourself,” he said, recalling his amazement at being in the Castro in 1993, even though the neighborhood was suffering under the AIDS epidemic.

After Mr. Wiener moved to San Francisco in 1997, he worked for a private law firm and then as a lawyer for the city before deciding to run for supervisor in District 8 in 2010.

By then, an increasing number of straight people, including couples with children, had moved to the Castro. Like many other neighborhoods, the Castro went through gentrification, which forced many longtime residents to move out.

Cleve Jones, a longtime Castro resident and gay rights activist who worked with Harvey Milk, a city supervisor who was killed in 1978, said he did not support Mr. Wiener in 2010 because he believed that the candidate’s policies favored businesspeople and developers. Mr. Jones said that overdevelopment, not the antinudity ban, threatened the character of the Castro.

“Many people who are supporting the band of nudists who have made their beachhead here clearly believe that encouraging this behavior will somehow help keep the neighborhood gay,” he said. “Now I don’t understand this equation between naked and gay.”

Mr. Wiener said he had taken on the nudists only reluctantly.

“For a year, I had people just pounding on me,” he said. “ ‘Why aren’t you doing something about this? If you don’t get rid of this, I’m never supporting you again.’ Then when I stated publicly that I was considering legislation to restrict it, other people were telling me, ‘If you do this, I’m never supporting you again.’